android.content.Intent#ACTION_NEW_OUTGOING_CALL源码实例Demo

下面列出了android.content.Intent#ACTION_NEW_OUTGOING_CALL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: QuranAndroid   文件: AudioManager.java
/**
 * Broadcast receiver to check outgoing call
 */
private void initOutgoingBroadcastReceiver() {
    OutgoingBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {

                isInCall = true;

                if (isInCall == true) {
                    smallMediaPlayer = SmallMediaPlayer.getInstance(context);
                    bigNotification = false;
                    pauseMedia();
                }

            }
        }
    };
    IntentFilter filter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
    context.registerReceiver(OutgoingBroadcastReceiver, filter);
}
 
@Test
public void activityShouldGetCorrectIntentData() {
    // prepare data for onReceive and call it
    Intent intent = new Intent(Intent.ACTION_NEW_OUTGOING_CALL);
    intent.putExtra(Intent.EXTRA_PHONE_NUMBER, "01234567890");

    mReceiver.onReceive(mContext, intent);
    assertNull(mReceiver.getResultData());

    // what did receiver do?
    verify(mContext, times(1)).startActivity(captor.capture());
    Intent receivedIntent = captor.getValue();
    assertNull(receivedIntent.getAction());
    assertEquals("01234567890", receivedIntent.getStringExtra("phoneNum"));
    assertTrue((receivedIntent.getFlags() &
            Intent.FLAG_ACTIVITY_NEW_TASK) != 0);
}
 
 方法所在类
 同类方法