end incoming call programmatically
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);
}
}
Related videos on Youtube
RuntimeException
Updated on December 07, 2020Comments
-
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 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 TelephonyManagerand 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 about 10 yearsAwesome, working like a charm! You saved me a lot of time, I'm confused why this post have so less of votes
-
bgplaya about 10 yearsWhat kind of exception you can catch there ? Did you try that working on different kinds of devices ?
-
bgplaya about 10 yearsActually I wanna know if that exceptions connected with reflection or with system services ?
-
Jebasuthan almost 10 years@GokulJai, Please let me know it throwing any error for you?. It's working fine for us.
-
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 over 9 yearsWhere to call this function?
-
Jebasuthan over 9 years@NarendraDroidWorm, You can call the function in your button click functions.
-
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 over 9 years@NarendraDroidWorm u got ur answer
-
Iman Marashi almost 9 yearsUnknown identifier: "com/android/internal/telephony/ITelephony.java". Falling back to search
-
greywolf82 almost 9 yearsI 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 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 over 8 years@Jeba will it end all types of calls ? or only the calls which user dialed ?
-
Sharp Edge over 8 yearsand what kind of permissions are required for this to work ?
-
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 about 8 yearsCan you please explain why you need
tmpBinder
? The parameters null, "fake" look a little strange -
Ashish Virani almost 2 yearsthis function not work in target version 30.