注册电话帐户

时间:2016-11-08 15:04:23

标签: android

我正在尝试实施ConnectionService。为此,我需要在TelecomService上注册一个电话帐户,因此设备会知道它可以使用我的应用程序拨打电话。

当我尝试注册一个电话帐户时,我收到一个SecurityException:包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);

1 个答案:

答案 0 :(得分:1)

也许您忘了申请许可:

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.
    }
}
相关问题