How do you programmatically end a call on 2.3+?

前端 未结 3 798
生来不讨喜
生来不讨喜 2020-12-24 04:04

Up to Android 2.2 I know I can use reflection and terminate the call through getITelephony.

However, as of 2.3 this no longer works because even if you grant the MO

3条回答
  •  一整个雨季
    2020-12-24 04:30

    private void endCall(final String cutofftime) {

    TelephonyManager telephony = (TelephonyManager) srvs
                .getSystemService(Context.TELEPHONY_SERVICE);
        Class c;
        final com.android.internal.telephony.ITelephony telephonyService;
        try {
            c = Class.forName("android.telephony.TelephonyManager");//telephony.getClass().getName());
            Log.i("TelephonyClass Name", telephony.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            telephonyService = (ITelephony) m.invoke(telephony);
            TimerTask task = new TimerTask() {
    
                @Override
                public void run() {
                    try {
                        if (telephonyService.isIdle()
                                || telephonyService.isOffhook()
                                || telephonyService.isRinging())
                            telephonyService.endCall();
                    } catch (RemoteException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            };
            long delay = Integer.parseInt(cutofftime) * 1000;
            new Timer().schedule(task, delay);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    

提交回复
热议问题