How to cancel outgoing call in android dev.?

China☆狼群 提交于 2019-12-23 04:33:08

问题


I just want to know if how to cancel outgoing call in android dev.? Is it possible in the simplest way of coding?


回答1:


You need to create a BroadCastReceiver that will be called on the action : NEW_OUTGOING_CALL

Java Class :

public class CallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, final Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){
            setResultData(null);
            abortBroadcast(); // cancel the call
        }
    }
}

Manifest declaration

Edit don't forget add out going permission

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 

<receiver android:name=".CallReceiver" >
    <intent-filter android:priority="2147483647" >
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

With this code, any call will be canceled and you will not be able to do a call if this app is on your phone




回答2:


1.Create a BroadcastReceiver with a priority of 0.

<receiver android:name=".YourReceiver" >
    <intent-filter android:priority="0" >
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>

2.In the BroadcastReceiver intercept the ACTION_NEW_OUTGOING_CALL intent in its onReceive method

public void onReceive(final Context context, final Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){
            setResultData(null);
        }
    }

3.call setResultData(null) in the onReceive as shown in above code/method

Add below permission in AndroidManifest.xml file

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 


来源:https://stackoverflow.com/questions/28793946/how-to-cancel-outgoing-call-in-android-dev

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