0

I need to hang up a phone call that I launched in background of my activity. The only solution I found to do so, is the answer of Jeba : end incoming call programmatically

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);
    }
}

This method works well to end a call, but I have a serious problem : all subsequent incoming calls are blocked, until I have force closed the application (from the applications manager).

I would like to stop this behavior after my activity finish and find again the normal behavior. I am not really comfortable with Itelephony.

Do you know a simpler method to promptly hang up a call from my activity without blocking everything ? Something that can work on all Android versions.

Or using the Jeba method, an idea to set Itelephony to accept calls again when I close my activity ?

Thanks for your help

Community
  • 1
  • 1
odgatelmand
  • 393
  • 1
  • 5
  • 16

1 Answers1

0

On my Nexus 5 (Android 6.0) I resolved my problem by deleting the following permission in the manifest.

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

To be honest, I don't understand why this permission blocked all my incoming calls.

But after testing on previous versions, without READ_PHONE_STATE Permission : Calls can't be launched. When READ_PHONE_STATE is active, I can't find again the normal behavior for incoming calls. If you can help, tell me. I am blocked on this problem since 2 days.

odgatelmand
  • 393
  • 1
  • 5
  • 16