Rejecting Incoming call in android

前端 未结 6 610
旧巷少年郎
旧巷少年郎 2020-12-01 02:37

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?

6条回答
  •  半阙折子戏
    2020-12-01 02:57

    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....");
    
            }
    

提交回复
热议问题