我想为 Voip 拨号器应用程序实现“android.telephony”库。所以根据这个https://developer.android.com/reference/android/telecom/ConnectionService我正在尝试注册PhoneAccount。我正在像下面那样做,
private void registerPhoneAcc(String calleeURI, String phoneNumber) {
TelecomManager telecomManager = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
telecomManager = (TelecomManager) getContext().getSystemService(Context.TELECOM_SERVICE);
}
ComponentName componentName = new ComponentName(getContext().getPackageName(), String.valueOf(MyConnectionService.class));
PhoneAccountHandle phoneAccountHandle = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
phoneAccountHandle = new PhoneAccountHandle(componentName,"App" );
PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, "Primary").setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER).build();
telecomManager.registerPhoneAccount(phoneAccount);
}
}
<service android:name=".app.MyConnectionService"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
尽管我已经包含了许可,但我得到了以下异常
W/System.err: java.lang.SecurityException: PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission.
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Parcel.readException(Parcel.java:2013)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Parcel.readException(Parcel.java:1959)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at com.android.internal.telecom.ITelecomService$Stub$Proxy.registerPhoneAccount(ITelecomService.java:1019)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.telecom.TelecomManager.registerPhoneAccount(TelecomManager.java:990)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at com.app.DialClass.registerPhoneAcc(DialClass.java:828)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at com.app.DialClass.handleMessage(DialClass.java:1114)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Looper.loop(Looper.java:176)
2021-02-03 13:58:39.260 24630-24630/com.ex.voip W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6651)
2021-02-03 13:58:39.260 24630-24630/com.ex.voip W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2021-02-03 13:58:39.260 24630-24630/com.ex.voip W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
显现,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ex.voip">
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.group.MICROPHONE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="false" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:allowBackup="true"
android:allowClearUserData="true"
android:fullBackupContent="false"
android:hardwareAccelerated="false"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:largeHeap="true"
android:usesCleartextTraffic="true"
android:resizeableActivity="false"
android:screenOrientation="portrait"
android:supportsRtl="true"
tools:replace="android:label,android:theme,android:icon"
android:theme="@style/AppThemeNoAction"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".app.LaunchActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"
android:theme="@style/FullscreenTheme"
tools:replace="android:icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".app.NetworkChangeReceiver"
android:label="NetworkChangeReceiver" />
<activity
android:name=".app.MainActivity"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"
android:theme="@style/AppThemeNoActionBar" />
<activity
android:name=".app.AboutActivity"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".app.SpeedActivity"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".app.Function"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"/>
<activity
android:name=".app.CallDetails"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".app.AccountDetails"
android:label="@string/title_activity_account_details"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"
android:theme="@style/AppThemeNoAction.NoActionBar"/>
<activity
android:name=".app.DetailsRecyclerView"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"/>
<service android:name=".app.pushnotifications.FCMBroadcastReceiver">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".app.StartService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".app.CallService"
android:exported="true"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<receiver android:name=".app.CallBroadcast"
android:exported="true"/>
<service
android:name=".app.VoipSupportService"
android:exported="false"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service android:name=".app.NotificationService"
android:exported="false"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service android:name=".app.MyConnectionService"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
</application>
</manifest>
像这样实现运行时权限https://stackoverflow.com/a/40490990/11630822
我对 BIND_TELECOM_CONNECTION_SERVICE 权限的请求被拒绝。
不知道这是什么原因。
提前致谢。