End a software call

This is a familiar question in SO. and I need the end call programmatically. I 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 /

Reject an 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 calling a mobile number and receiving messages in Android application development?

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

and many more questions, answers and suggestions ...

Everyone says use ITelephonyService.aidl in conjunction with TelephonyManager

and the solution works fine on many devices, but doesn't work on the Samsung S Duos . I have been fighting for a week, but have not received a solution. Is there any special API for working with this type of device? How can I reject an incoming call? please help me...

+20
android telephonymanager telephony
Jan 07 '14 at 6:57
source share
3 answers

Try it. Of course it will work. It works great for me.

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

After that, you add a method to end the call:

Call Off Function

 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); } } 
+59
Jan 09 '14 at 7:16
source share

Try this feature:

  private void endCall() { Context context = getApplicationContext(); try { TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephonyService = (ITelephony) m.invoke(telephony); // Funciona en 2.2 // Funciona en 2.3.3 telephonyService.endCall(); logManager.debug("ITelepony was used (endCall)"); } catch (Exception e) { logManager.error("Error ending call: " + e.getMessage()); logManager.debug("Error ending call", e); } } 
0
Jul 01 '14 at 8:23
source share

In the application, create the package (com.android.internal.telephony) in the java folder. And then copy the ITelephone interface into this package

ITelephone interface source: http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/com/android/internal/telephony/ITelephony.java/?v= source

Code to disconnect a call:

 Context context = getApplicationContext(); try { TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephonyService = (ITelephony) m.invoke(telephony); telephonyService.answerRingingCall(); } catch (Exception e) { } 

Also add permissions to use these methods:

 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" /> 
-one
Apr 19 '16 at 7:47
source share



All Articles