how to end up my outgoing call.

心已入冬 提交于 2020-01-02 05:03:10

问题


with statrtActivity(callIntent), call goes and then i have to wait for few seconds and end automatically. to end up my call i have taken mycalss extends Broadcastreceiver then in that onreceive() i implemented.in that method i got only to set old number and newnumber and toast is printing. What i want exactly is to end call what i need to write. and how to call onreceive method from my class? plase help me. i didnt get anywhere.

 @Override
                public void onReceive(Context context, Intent intent) {                                 
                    final String oldNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);         
                    this.setResultData(newPhNnumber);                                                   
                    final String newNumber = this.getResultData();
                    if((newNumber!=null)&&(newNumber!=oldNumber))
                    {
                    String msg = "Intercepted outgoing call. Old number " + oldNumber + ", new number " + newNumber;
                    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
                    this.abortBroadcast();----> what it does?
                }

回答1:


You may try this:

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
    Class c = Class.forName(tm.getClass().getName());
    Method m = c.getDeclaredMethod("getITelephony");
    m.setAccessible(true);
    ITelephony telephonyService = (ITelephony) m.invoke(tm);

    telephonyService.endCall();

} catch (Exception e) {
    e.printStackTrace();
}



回答2:


you simply abort outgoing call through following code

public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    if (intent.getAction()
            .equals("android.intent.action.NEW_OUTGOING_CALL")) {

        phoneNo = intent
                .getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        if (phoneNo.isBlocked(blockNo)) {
            setResultData(null);

        }
    }
}


来源:https://stackoverflow.com/questions/9408476/how-to-end-up-my-outgoing-call

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