4

I'm trying to implement ConnectionService. For this I need to register a phone account on TelecomService, so the device will know it can use my app for making phone calls.

When I try to register a phone account I get a SecurityException: Package com.xxx.xxx does not belong to 10145.

What am I missing? Here is the code to register a phone account. (I have added the permission to the manifest etc)

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
    Check this answer https://stackoverflow.com/questions/40461292/i-need-help-to-get-cnapcallerdisplayname-in-android/42948594#42948594 – Jose Riballo Apr 12 '18 at 11:11

1 Answers1

1

Maybe you forgot to declare permission:

android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"

And take care to request this permission for Marshmellow and higher android version. 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.
    }
}