无法在电信服务上注册新的phoneAccount

时间:2018-04-13 05:15:36

标签: java android react-native

我正在尝试注册一个新的phoneAccount,但我一直收到以下错误:

04-13 01:06:11.329  1267  2435 W Telecom : com.android.server.telecom.PhoneAccountRegistrar: phoneAccount ComponentInfo{com.my.otherApp/com.my.app.RNCallConnectionService} not found: TSI.rPA@Agc
04-13 01:06:11.329  1267  2435 W Telecom : com.android.server.telecom.PhoneAccountRegistrar: Phone account ComponentInfo{com.my.otherApp/com.my.app.RNCallConnectionService}, [a50dcea6cba1c8c30324624e9e54bfd19bb0b363], UserHandle{0} does not have BIND_TELECOM_CONNECTION_SE
RVICE permission.: TSI.rPA@Agc
04-13 01:06:11.330  1267  2435 E Telecom : com.android.server.telecom.TelecomServiceImpl$1: registerPhoneAccount [[ ] PhoneAccount: ComponentInfo{com.my.otherApp/com.my.app.RNCallConnectionService}, [a50dcea6cba1c8c30324624e9e54bfd19bb0b363], UserHandle{0} Capabilities: C
allProvider  Schemes: tel  Extras: null]: TSI.rPA@Agc
04-13 01:06:11.330  1267  2435 E Telecom : java.lang.SecurityException: PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission.
04-13 01:06:11.330  1267  2435 E Telecom :      at com.android.server.telecom.PhoneAccountRegistrar.registerPhoneAccount(PhoneAccountRegistrar.java:587)
04-13 01:06:11.330  1267  2435 E Telecom :      at com.android.server.telecom.TelecomServiceImpl$1.registerPhoneAccount(TelecomServiceImpl.java:399)
04-13 01:06:11.330  1267  2435 E Telecom :      at com.android.internal.telecom.ITelecomService$Stub.onTransact(ITelecomService.java:226)
04-13 01:06:11.330  1267  2435 E Telecom :      at android.os.Binder.execTransact(Binder.java:573)

我确保将<uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>添加到我的清单中。

以下是相关代码

public class RNCallModule extends ReactContextBaseJavaModule {

    static private String TAG = "RNCallModule +++++";

    private ReactApplicationContext reactContext;

    private String appName;

    private TelecomManager tm;

    private PhoneAccountHandle handle;

    private PhoneAccount phoneAccount;

    public RNCallModule(ReactApplicationContext reactContext) {
        super(reactContext);

        this.reactContext = reactContext;

        Boolean a = PackageManager.PERMISSION_GRANTED == this.reactContext.checkCallingOrSelfPermission(Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE);

        appName = getApplicationName(this.reactContext.getApplicationContext());

        ComponentName cName = new ComponentName(this.reactContext.getApplicationContext(), RNCallConnectionService.class);

        handle = new PhoneAccountHandle(cName, appName);

        tm = (TelecomManager)this.reactContext.getApplicationContext().getSystemService(this.reactContext.getApplicationContext().TELECOM_SERVICE);

        if(android.os.Build.VERSION.SDK_INT >= 26) {
            phoneAccount = new PhoneAccount.Builder(handle, appName)
                    .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
                    .build();
            tm.registerPhoneAccount(phoneAccount);
        }

        phoneAccount = new PhoneAccount.Builder(handle, appName)
                .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
                .build();


        tm.registerPhoneAccount(phoneAccount); // <<<<<< Here is where the error happens 

    }

    // ... 

}

1 个答案:

答案 0 :(得分:0)

即使我在AndroidManifest.xml上添加了权限,我仍然需要添加这个额外的位:

<service android:name="com.my.app.RNCallConnectionService"
    android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
    <intent-filter>
        <action android:name="android.telecom.ConnectionService" />
    </intent-filter>
</service>