0

It is possible to end a phone call programmatically without even using ITelephony.aidl.

But how can one close com.android.phone.InCallScreen that comes on top of the activity stack right after that?

It closes automatically after about 4 seconds, but I would like to close it immediately.

Community
  • 1
  • 1
A.G.
  • 2,037
  • 4
  • 29
  • 40

1 Answers1

0

Try this Sure it will work. It's working fine for me. Please try and let me know.

You could download the ITelephony.java file from ITelephony.java

After that you add the method to end call:

Function to Disconnect call

public void disconnectCall(){
 try {

    String serviceManagerName = "android.os.ServiceManager";
    String serviceManagerNativeName = "android.os.ServiceManagerNative";
    String telephonyName = "com.android.internal.telephony.ITelephony";
    Class<?> telephonyClass;
    Class<?> telephonyStubClass;
    Class<?> serviceManagerClass;
    Class<?> serviceManagerNativeClass;
    Method telephonyEndCall;
    Object telephonyObject;
    Object serviceManagerObject;
    telephonyClass = Class.forName(telephonyName);
    telephonyStubClass = telephonyClass.getClasses()[0];
    serviceManagerClass = Class.forName(serviceManagerName);
    serviceManagerNativeClass = Class.forName(serviceManagerNativeName);
    Method getService = // getDefaults[29];
    serviceManagerClass.getMethod("getService", String.class);
    Method tempInterfaceMethod = serviceManagerNativeClass.getMethod("asInterface", IBinder.class);
    Binder tmpBinder = new Binder();
    tmpBinder.attachInterface(null, "fake");
    serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder);
    IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone");
    Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class);
    telephonyObject = serviceMethod.invoke(null, retbinder);
    telephonyEndCall = telephonyClass.getMethod("endCall");
    telephonyEndCall.invoke(telephonyObject);

  } catch (Exception e) {
    e.printStackTrace();
    Log.error(DialerActivity.this,
        "FATAL ERROR: could not connect to telephony subsystem");
    Log.error(DialerActivity.this, "Exception object: " + e); 
 }
}
Jebasuthan
  • 5,538
  • 6
  • 35
  • 55
  • Sorry, this doesn't close the InCallScreen immediately. It hangs for a few seconds and then closes automatically after a few seconds, like in this solution: http://stackoverflow.com/questions/18977012/why-itelephony-aidl-works – A.G. Jan 23 '14 at 18:03
  • Ok I agree with you. I am using this one code only to end a call programmtically. If you found better solution please let me know. Thanks for your valuable information. Thanks – Jebasuthan Jan 24 '14 at 03:20