Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rejecting Incoming call in android

I want to reject incoming in android, I have seen so many code from these links.

  1. Android: Taking complete control of phone(kiosk mode), is it possible? How?

  2. How to Reject a call programatically in android

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

  4. http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html?showComment=1361478035090#c5468022990217431781

But I am still unable to do it, can anybody tell me in simple and easy steps how to do it?

like image 928
Zubair Avatar asked Feb 21 '13 20:02

Zubair


People also ask

How do I decline an incoming call on Android?

To reject the call, swipe the white circle to the bottom of the screen when your phone is locked, or tap Dismiss. Rejected callers can leave a message.

What happens when you reject a call on Android?

If you're declining someone's call, both Android and iPhone models have a 'Send Message' option. To avoid confrontation later, tap on this (it will silence the call) and send the caller a message that you're busy.

Why does my Android keep rejecting incoming calls?

The most common reasons are the flight mode, call barring, call forwarding or call auto-reject.


2 Answers

In order to intercept your call you just have to:
1. Make a package named. com.android.internal.telephony;
2. In this package make a interface file named ITelephony.
and write this code in that interface file.

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

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

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

Thats it.

like image 141
4 revs, 2 users 88% Avatar answered Sep 21 '22 13:09

4 revs, 2 users 88%


Provide appropriate permission and add the 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....");

        }
like image 26
Ajay Pandya Avatar answered Sep 17 '22 13:09

Ajay Pandya