0

我想在 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 个

4

3 回答 3

0

MODIFY_PHONE_STATE是系统权限,您可以根设备并将您的应用程序放在 /system/priv-app 文件夹中。但是还有其他方法可以解决您的问题。你到底想在这里实现什么。

看看这里

MODIFY_PHONE_STATE 是系统独有的权限,因此不允许应用获取它。

这可能与以前版本的平台有所不同,但这没关系,因为它只保护私有 API,所以如果你正在做一些需要它的事情,你正在使用不受支持的私有 API,这会导致像你的应用程序这样的事情打破平台的不同版本。

您包含的堆栈爬网不完整,因此无法判断您实际在做什么。

于 2019-07-16T06:43:58.337 回答
0

正如cantona_7提到的 MODIFY_PHONE_STATE 是系统唯一权限,如果没有 root 访问权限,您将无法访问它,并且没有解决方法可以终止从 pie 开始的呼叫。

正如官网所说:

MODIFY_PHONE_STATE 在 API 级别 1 中添加 public static final String MODIFY_PHONE_STATE

允许修改电话状态 - 开机、mmi 等。不包括拨打电话。

不供第三方应用程序使用。

于 2019-07-16T07:00:48.430 回答
0

使用 TelecomManger 使用 ANSWER_PHONE_CALL 权限以编程方式结束 Android 9 及更高版本的呼叫。

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
    TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
    if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_GRANTED) {
        success = tm.endCall();
        Log.d("call state", "call end");
    }
}
于 2022-01-17T07:51:21.250 回答