I was using the code below to end a call. But now on Oreo, I'm getting an error which states that the MODIFY_PHONE_STATE
permission is required and hence this code is no longer working.
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Toast.makeText(context, "here", Toast.LENGTH_LONG).show();
assert telephonyManager != null;
Class clazz = Class.forName(telephonyManager.getClass().getName());
Method method = clazz.getDeclaredMethod("getITelephony");
method.setAccessible(true);
ITelephony telephonyService;
telephonyService = (ITelephony) method.invoke(telephonyManager);
telephonyService.silenceRinger();
telephonyService.endCall();
Furthermore, as per docs and many blogs, MODIFY_PHONE_STATE
permission is valid for system apps only.
So now how we will end calls in future?
Is there any other way.
Error:
java.lang.SecurityException: MODIFY_PHONE_STATE permission required.
at android.os.Parcel.readException(Parcel.java:2004)
at android.os.Parcel.readException(Parcel.java:1950)
W/System.err: at com.android.internal.telephony.ITelephony$Stub$Proxy.endCall(ITelephony.java:2025)