Interrupting a call


SDK Version: 
M3

end callAs far as I know there is no public API for interrupting/ending a call. You can detect calls and the states of calls, maybe even prevent an outgoing call, but there is no API for ending an ongoing call.
This must be a security issue, but I also met the need of this feature, and only was able to do some workaround: turning on airplane mode interrupts all wireless connections including phone calls.

The problem is that this method has side effects like, interrupting Internet connection, makes the phone completely unavailable for incoming calls too and I'm not sure how does it affect emergency calls. The phone number can be checked so the emergency call issue can be solved anyway. My main problem was, that turning off the airplane mode requires PIN code, so even if we programmatically turn it on, and immediately off the airplane mode the user is forced to enter PIN code, and the device cannot even receive incoming calls.

So if anyone knows a better solution in the community please share with us.

Lets see some sample code for detecting an outgoing call and turning on airplane mode.

Detecting a call can be done with creating a Broatcastreciever, and registring it into the AndroidManifest like below:

  1. public class CallReceiver extends BroadcastReceiver {
  2.   @Override
  3.   public void onReceive(Context arg0, Intent arg1) {
  4.     //this method runs on new outgoing call
  5.   }
  6. }

  1. <receiver android:name=".CallReceiver">
  2.   <intent-filter>
  3.     <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
  4.   </intent-filter>
  5. </receiver>

The airplane can be turned on like this:

  1. android.provider.Settings.System.putInt(context.getContentResolver(android.provider.Settings.System.AIRPLANE_MODE_ON, 1);
  2. Intent airplaneIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
  3. airplaneIntent.putExtra("state", 1);
  4. context.sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE"));
  5. context.sendBroadcast(airplaneIntent);

You can combine the two, start an alarmaManager and turn the airplane mode on, and after a given amount of time interrupt the call.