Reject an incoming call in android

I want to reject incoming in android, I saw so much code from these links.

But I still can’t do this, can someone tell me simple and easy steps how to do this?

+12
android telephony incoming-call
Feb 21 '13 at
source share
5 answers

To intercept your call, you just need to:
1. Make a package with a name. com.android.internal.telephony;
2. In this package, create an interface file named ITelephony.
and write this code in this interface file.

boolean endCall(); void answerRingingCall(); void silenceRinger(); 

Now in your class where you want to intercept the call, extend this class to BroadcastReceiver and write the following code in the onReceive() function.

 TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); telephonyService = (ITelephony) m.invoke(tm); Bundle bundle = intent.getExtras(); String phoneNumber = bundle.getString("incoming_number"); Log.d("INCOMING", phoneNumber); if ((phoneNumber != null)) { telephonyService.endCall(); Log.d("HANG UP", phoneNumber); } } catch (Exception e) { e.printStackTrace(); } 

Here it is.

+14
Feb 22 '13 at 20:38
source share

Grant appropriate permission and add ITelephony.java file

 private void declinePhone(Context context) throws Exception { 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.d("unable", "msg cant dissconect call...."); } 
+3
Feb 12 '15 at 5:56
source share

You will need a broadcast receiver for this with an intent filter, I think ACTION_ANSWER

more about this here: http://developer.android.com/reference/android/content/Intent.html#ACTION_ANSWER

You can register it using the manifest file or the registerReceiver method

more details here: http://developer.android.com/reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver , android.content.IntentFilter)

You also need to specify the appropriate permissions in the manifest file.

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

The links you provided are pretty good. You just need more patience :)

happy coding.

+1
Feb 21 '13 at 21:09
source share

Create an interface in com.android.internal.telephony and name as

 interface ITelephony { /** * Demonstrates some basic types that you can use as parameters * and return values in AIDL. */ void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString); boolean endCall(); void silenceRinger();strong text void answerRingingCall(); } // then catch the incoming call intent and call below method if (intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER) != null) { number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); Toast.makeText(context, "INCOMING call catched: ", Toast.LENGTH_SHORT).show(); disconnectPhoneItelephony(mContext) } private void disconnectPhoneItelephony(Context context) { ITelephony telephonyService; TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); SessionManager.getInstance(context).setBlockStatusAllow("BLOCKED"); telephonyService = (ITelephony) m.invoke(telephony); telephonyService.silenceRinger(); telephonyService.endCall(); } catch (Exception e) { e.printStackTrace(); } } 

Add required permission in manifest

0
Aug 08 '16 at 6:09
source share

This is the best tutorial for blocking all incoming calls that you can configure to block an incoming call for only selected numbers.

Android Incoming Call Blocking

0
Apr 26 '17 at 14:11
source share



All Articles