我正在尝试实施连接服务 https://developer.android.com/reference/android/telecom/ConnectionService.html。为此,我需要在 TelecomService 上注册一个电话帐户,以便设备知道它可以使用我的应用程序拨打电话。
当我尝试注册电话帐户时,出现 SecurityException:Package com.xxx.xxx 不属于 10145。
我缺少什么?这是注册电话帐户的代码。 (我已将权限添加到清单等中)
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"
请注意为 Marshmallow 和更高版本的 Android 请求此权限。在运行时请求权限 https://developer.android.com/training/permissions/requesting.html
// 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.
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)