Interrupt incoming call in android

后端 未结 1 386
攒了一身酷
攒了一身酷 2021-01-06 19:12

How to open a custom UI on incoming call with answer and reject button on it,I want to show custom UI instead of default dialer. I am using below code but dialer is open and

相关标签:
1条回答
  • 2021-01-06 19:21

    First do the following :

    try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    

    then call the abortBroadcast() method before calling your activity and make sure to put a priority in your intentFilter like the following :

     <intent-filter android:priority="99999" >
                <action android:name="android.intent.action.PHONE_STATE" />
      </intent-filter>
    

    and to answer the incoming phone call from the custom UI do the following :

    answerButton = (Button) findViewById(R.id.pickup);
        answerButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                Intent answer = new Intent(Intent.ACTION_MEDIA_BUTTON);
                answer.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,   KeyEvent.KEYCODE_HEADSETHOOK));
         context.sendOrderedBroadcast(answer, null);
    
            }
        });
    

    and to reject the call do the following :

    rejectButton= (Button) findViewById(R.id.pickup);
        rejectButton= .setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
        buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
        getApplicationContext().sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");
    
    
        }
    });
    

    Hope that helps

    0 讨论(0)
提交回复
热议问题