endCall在android中使用ITelephony无效

时间:2015-11-26 07:53:36

标签: java android sqlite

我正在开发一个呼叫拦截器项目。我使用过iTelephony软件包但 endCall()函数无效。任何人都可以建议我这段代码中的问题是什么?提前致谢

 private void disconnectPhoneItelephony(Context context)
{
    CharSequence text = "In the disconnect function toast!";
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
    ITelephony telephonyService;
    TelephonyManager telephony = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);
    /*changed*/
    //telephony.listen(new TeleListener(), PhoneStateListener.LISTEN_CALL_STATE);
    //TelephonyManager.CALL_STATE_RINGING;
    try
    {
        text = "Action State: " + TelephonyManager.CALL_STATE_RINGING + "toast!";
       // text = "Action " + TelephonyManager.CALL_STATE_RINGING + "toast!";
       duration = Toast.LENGTH_SHORT;
        toast = Toast.makeText(context, text, duration);
        toast.show();

         Class c = Class.forName(telephony.getClass().getName());
        text = "Action State: " + c.toString() + "toast!";
        duration = Toast.LENGTH_SHORT;
        toast = Toast.makeText(context, text, duration);
        toast.show();
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        telephonyService = (ITelephony) m.invoke(telephony);
        telephonyService.endCall();
      // Log.i(this.LOG_TAG, "Call ended");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:0)

您是否拥有必要的权限?

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

P.S。此代码不适用于所有手机型号,导致某些制造商覆盖TelephonyManager