jeudi 26 novembre 2015

endCall is not working using ITelephony in android

I am working on a call blocker project. I have used iTelephony package but the endCall() function is not working. Can anyone suggest me what is the problem in this code snippet ? Thanks in advance

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

Aucun commentaire:

Enregistrer un commentaire