1

I am trying to kill a phone call programatically in Android Oreo.

Here is my source code.

  public boolean killCall(Context context) {
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Method m1 = tm.getClass().getDeclaredMethod("getITelephony");
        m1.setAccessible(true);
        Object iTelephony = m1.invoke(tm);

        Method m2 = iTelephony.getClass().getDeclaredMethod("silenceRinger");
        Method m3 = iTelephony.getClass().getDeclaredMethod("endCall");

        m2.invoke(iTelephony);
        m3.invoke(iTelephony);

    } catch (Exception ex) { // Many things can go wrong with reflection calls
        Log.d(TAG,"PhoneStateReceiver **" + ex.getCause());
        ex.getCause().printStackTrace();
        return false;
    }
    return true;
}

But I get Exception java.lang.SecurityException: Neither user 10187 nor current process has android.permission.CALL_PHONE.

Although I have defined permission in manifest

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

I am also taking run time permissions using a popup, and when I view application permissions, the phone permission is enabled there too. I am wondering why this happening and amazingly this happening on Android Oreo only, not on lower versions. Any helpful suggestion would be wonderful.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ali Akram
  • 4,803
  • 3
  • 29
  • 38

0 Answers0