end incoming call programmatically

RuntimeException picture RuntimeException · Jan 7, 2014 · Viewed 23k times · Source

This is a familiar question in SO. and what I need is to end call programmatically. I have searched a lot...

http://androidsourcecode.blogspot.in/2010/10/blocking-incoming-call-android.html http://androiddesk.wordpress.com/2012/08/02/blocking-a-call-without-user-intervention-in-android/

Rejecting Incoming call in android

How to programmatically answer/end a call in Android 4.1?

http://www.emoticode.net/android-sdk/block-incoming-and-outgoing-phone-calls-programmatically.html

How to block calls in android

how to block a mobile number call and message receiving in android application development?

and http://androidsourcecode.blogspot.in/2010/10/blocking-incoming-call-android.html

and lot more questions, answers and suggestions...

All are saying use ITelephonyService.aidl in combination with TelephonyManager

and the solution is working perfect on many devices but it's not working on Samsung S Duos. I am struggling over a week but didn't get a solution.. is there any special API to work with on this type of devices? How can I reject incoming call? please help me...

Answer

Jebasuthan picture Jebasuthan · Jan 9, 2014

Try this Sure it will work. It's working fine for me.

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