Reputation: 11
I just want to know if how to cancel outgoing call in android dev.? Is it possible in the simplest way of coding?
Upvotes: 0
Views: 2535
Reputation: 4997
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
Upvotes: 3
Reputation: 6345
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" />
Upvotes: 1