我想在 android 9 pie 中以编程方式终止调用。
我使用了这段代码,但它只适用于奥利奥。它不适用于派
public static boolean killCall(Context context) {
try {
System.out.println("Kill called");
// Get the boring old TelephonyManager
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Get the getITelephony() method
Class classTelephony = Class.forName(telephonyManager.getClass().getName());
Method methodGetITelephony = classTelephony.getDeclaredMethod("getITelephony");
// Ignore that the method is supposed to be private
methodGetITelephony.setAccessible(true);
// Invoke getITelephony() to get the ITelephony interface
Object telephonyInterface = methodGetITelephony.invoke(telephonyManager);
// Get the endCall method from ITelephony
Class telephonyInterfaceClass =
Class.forName(telephonyInterface.getClass().getName());
Method methodEndCall = telephonyInterfaceClass.getDeclaredMethod("endCall");
// Invoke endCall()
methodEndCall.invoke(telephonyInterface);
System.out.println("Killed");
inCall = false;
} catch (Exception ex) { // Many things can go wrong with reflection calls
ex.printStackTrace();
Log.d(TAG, "PhoneStateReceiver **" + ex.toString());
System.out.println("Error");
return false;
}
return true;
}
在 android pie 上运行时会出现此错误。谁能建议我和另一种终止通话的方法。
需要 MODIFY_PHONE_STATE 权限。在 android.os.Parcel.createException(Parcel.java:1942) 在 android.os.Parcel.readException(Parcel.java:1910) W/System.err: 在 android.os.Parcel.readException(Parcel.java:1860 ) 在 com.android.internal.telephony.ITelephony$Stub$Proxy.endCall(ITelephony.java:2249) ... 还有 10 个