end incoming call programmatically

23,668

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); 
 }
}
Share:
23,668

Related videos on Youtube

RuntimeException
Author by

RuntimeException

Updated on December 07, 2020

Comments

  • RuntimeException
    RuntimeException over 3 years

    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...

  • bgplaya
    bgplaya about 10 years
    Awesome, working like a charm! You saved me a lot of time, I'm confused why this post have so less of votes
  • bgplaya
    bgplaya about 10 years
    What kind of exception you can catch there ? Did you try that working on different kinds of devices ?
  • bgplaya
    bgplaya about 10 years
    Actually I wanna know if that exceptions connected with reflection or with system services ?
  • Jebasuthan
    Jebasuthan almost 10 years
    @GokulJai, Please let me know it throwing any error for you?. It's working fine for us.
  • challa sathish kumar
    challa sathish kumar over 9 years
    @Jeba , by using above code, call is disconnect after one ring. is there any posibility without single ring.?
  • Narendra Singh
    Narendra Singh over 9 years
    Where to call this function?
  • Jebasuthan
    Jebasuthan over 9 years
    @NarendraDroidWorm, You can call the function in your button click functions.
  • Narendra Singh
    Narendra Singh over 9 years
    @Jeba: so, my question is - which call it will disconnect, the only incoming call or the others too. As, if the incoming call start ringing on the same time, when another call in progress. What will happen on calling this?
  • Erum
    Erum over 9 years
    @NarendraDroidWorm u got ur answer
  • Iman Marashi
    Iman Marashi almost 9 years
    Unknown identifier: "com/android/internal/telephony/ITelephony.java". Falling back to search
  • greywolf82
    greywolf82 almost 9 years
    I can confirm that this method works even on Android Lollipop (tested on 5.1.1). The "collateral" effect is that the user doesn't see the missed call notification, however it works great.
  • Mohammad
    Mohammad over 8 years
    @Jeba Man you SAVED ME! Thanks a ton. this method working great even after enabling proguard and this was my big problem. thanks :)
  • Sharp Edge
    Sharp Edge over 8 years
    @Jeba will it end all types of calls ? or only the calls which user dialed ?
  • Sharp Edge
    Sharp Edge over 8 years
    and what kind of permissions are required for this to work ?
  • Sharp Edge
    Sharp Edge about 8 years
    @Jeba can you please write a step by step tutorial for this? Some how it doesn't work on my Sony Xperia C2305, JellyBean. :(
  • Maksim Dmitriev
    Maksim Dmitriev about 8 years
    Can you please explain why you need tmpBinder? The parameters null, "fake" look a little strange
  • Ashish Virani
    Ashish Virani almost 2 years
    this function not work in target version 30.