Android - How to immediately endCall with telephonyService?

女生的网名这么多〃 提交于 2019-12-12 01:34:13

问题


In my application, there's a feature that ends outgoing call (and starts other activities) while dialing a certain number (e.g. *123*)

It's currently working, but requires a 200ms delay. Without the delay, the intent cannot be recieved.

The delay causes a consequence of multiple screen flickers:

my activity shows -> switch to call -> end call -> switch back to my activity

public class OutgoingCallListener extends BroadcastReceiver {
    // ...
    public void onReceive(final Context context, Intent intent) {
        // ...
        if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
            // ...
            if(number.equals("*123*")) {
                // ...
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    public void run() {
                        telephonyService.endCall();
                    }
                }, 200);
            }
        }
    }
}

I'v seen other applications with this special-number-dialing feature, the call ends immediately wihout the end-call-beep, and switches to app activity without flickering.

Q1: Does anyone know how to end call without delay? Is there another intent that we can catch before ACTION_NEW_OUTGOING_CALL?

Q2: On a mobile phone with low specs (slow CPU, less memory), would BroadcastReceiver work the same way as on a decent phone?


回答1:


Got the answer...

To end an outgoing call immediately, we don't even need to call endCall() from ITelephony, instead, we can simply use setResultData(null);

It's different from manually ending a call or using endCall, with setResultData(null):

  • No notification icon or message
  • No calling screen
  • No call time toast
  • No call log
  • No end call beep

It's just like nothing happened (if...without any other extra activities).

public class OutgoingCallListener extends BroadcastReceiver {
    // ...
    public void onReceive(final Context context, Intent intent) {
        // ...
        if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
            // ...
            if(number.equals("*123*")) {
                setResultData(null);
                // start other activities
            }
        }
    }
}



回答2:


Q1: Does anyone know how to end call without delay?

here is the answer Blocking/Ending incoming call

Is there another intent that we can catch before ACTION_NEW_OUTGOING_CALL?

No

Q2: On a mobile phone with low specs (slow CPU, less memory), would BroadcastReceiver work the same way as on a decent phone?

Yes



来源:https://stackoverflow.com/questions/14460915/android-how-to-immediately-endcall-with-telephonyservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!