gpt4 book ai didi

Android ConnectionService - 注册电话帐户时出现SecurityException

转载 作者:行者123 更新时间:2023-11-29 01:14:57 27 4
gpt4 key购买 nike

我正在尝试实现 ConnectionService .为此,我需要在 TelecomService 上注册一个电话帐户,这样设备就会知道它可以使用我的应用程序调用电话。

当我尝试注册电话帐户时,出现安全异常:包 com.xxx.xxx 不属于 10145。

我错过了什么?这是注册电话帐户的代码。 (我已将权限添加到 list 等)

PhoneAccountHandle   phoneAccountHandle = new PhoneAccountHandle(new ComponentName("com.mypackage", "com.mypackage.MyConnectionService", "my_phoneHandleId");
PhoneAccount.Builder builder = PhoneAccount.builder(phoneAccountHandle, "Custom label");

builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT | PhoneAccount.CAPABILITY_CONNECTION_MANAGER);
builder.addSupportedUriScheme("my_scheme");
builder.setAddress(Uri.parse("my_scheme://" + "customNumber"));

PhoneAccount phoneAccount = builder.build();
telecomService.registerPhoneAccount(phoneAccount);

最佳答案

也许你忘了声明权限:

android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"

并注意为 Marshmellow 和更高的 android 版本请求此权限。 Requesting Permissions at Run Time

    // Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE)
!= PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE)) {

// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.

} else {

// No explanation needed, we can request the permission.

ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE},
MY_PERMISSIONS_REQUEST_BIND_TELECOM_CONNECTION_SERVICE);

// MY_PERMISSIONS_REQUEST_BIND_TELECOM_CONNECTION_SERVICE is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}

关于Android ConnectionService - 注册电话帐户时出现SecurityException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40490227/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com