No such method getITelephony to disconnect Call

后端 未结 3 1353
既然无缘
既然无缘 2020-12-16 01:38

i want to disconnect outgoing call in ICS.

My issue is first of all I am not getting the broadcast in IC` in Gingerbread it is working fine and blocking the calls bu

3条回答
  •  悲&欢浪女
    2020-12-16 02:21

    1) Download this class : ITelephony

    2) Add this class.java in your project in package: com.android.internal.telephony

    3) Add this permission in your manifest :

    
    
    
    

    And this receiver in application balise :

    
       
         
       
    
    

    4) Create CallReceiver class :

    @Override
    public void onReceive(Context context, Intent intent) {
        ITelephony telephonyService = getTeleService(context);
        if(telephonyService!=null) {
            try {
                String numberCall = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                Log.i("TAG", "CALL NUM: " + numberCall);
                if(numberCall.equals(TEST_NUMBER)) {
                    telephonyService.endCall();
                    Toast.makeText(context, "END CALL: " + numberCall, Toast.LENGTH_LONG).show();
                    Log.i("TAG", "END CALL");
                } else {
                    Log.i("TAG", "ACCEPT CALL");
                }
            } catch (Exception e) {
                e.printStackTrace();
                Log.i("TAG", "CATCH CALL");
            }
        }
    }
    
    private ITelephony getTeleService(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        try {
            Method m = Class.forName(tm.getClass().getName()).getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            return (ITelephony) m.invoke(tm);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    

提交回复
热议问题