Android电信系统角色管理器
我正在尝试实现一个调用应用程序。对于API<29,我可以选择我的拨号程序应用程序作为默认拨号程序。但是对于API>=29,我无法获得显示提示,也无法在设置下将我的应用程序设置为默认拨号程序。它不显示为一个选项。不过,它与API<29的情况相同。 这是我的舱单:Android电信系统角色管理器,android,android-service,android-manifest,android-permissions,android-developer-api,Android,Android Service,Android Manifest,Android Permissions,Android Developer Api,我正在尝试实现一个调用应用程序。对于API=29,我无法获得显示提示,也无法在设置下将我的应用程序设置为默认拨号程序。它不显示为一个选项。不过,它与API
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ceptor">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Ceptor">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.CALL" />
<action android:name="android.intent.action.CALL_BUTTON" />
<action android:name="android.intent.action.ANSWER" />
<action android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<!-- The directives below this comment seem to be sufficient for API < 29 -->
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<!-- The directives above this comment seem to be sufficient for API < 29 -->
<action android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.CALL" />
<action android:name="android.intent.action.CALL_BUTTON" />
<action android:name="android.intent.action.ANSWER" />
</intent-filter>
</activity>
<receiver android:name=".CeptorBootCompleteReceiver" android:directBootAware="true" >
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service android:name=".CeptorConnectionService"
android:label="The_label_for_my_connection_service"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
</application>
</manifest>
所以我们在这里看到,我正在为我的角色管理器使用角色服务和角色拨号器。
然而,我从来没有得到过提示。从这里读到:
我看到上面写着:
要使角色管理器正确地解析请求,您的清单必须为要正确保留的角色指定类别、权限或其他意图筛选器。如果您未能这样做,请求将自动取消
但即使在Android官方文档中,我也没有看到角色拨号器的具体类别、权限或其他意图过滤器的确切列表
我认为API之间的区别在于旧的API使用TelecomManager的意图,而新的API使用新的角色管理器。我想就是这样,但也许我已经走远了
总之。。。为什么这对API<29有效,但在其他情况下无效?
应该是
// change from com.google.android.dialer
if (Build.VERSION.SDK_INT >= 29)
{
RoleManager rm = (RoleManager) getSystemService(Context.ROLE_SERVICE);
Intent intent = rm.createRequestRoleIntent(RoleManager.ROLE_DIALER);
startActivityForResult(intent, 1);
}
else
{
Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, this.getPackageName());
startActivity(intent);
}
TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
// Create a new PhoneAccountHandle with the name "CeptorHandle" which uses my CeptorConnectionService.
ComponentName cn = new ComponentName("com.example.ceptor", "com.example.ceptor.CeptorConnectionService");
PhoneAccountHandle pah = new PhoneAccountHandle(cn,"CeptorHandle");
// Create a new phone account which is associated with the PhoneAccountHandle "CeptorHandle".
final int capabilities = PhoneAccount.CAPABILITY_CALL_PROVIDER |
PhoneAccount.CAPABILITY_CONNECTION_MANAGER;
PhoneAccount pa = PhoneAccount.builder(pah, "CeptorHandle").setCapabilities(capabilities).build();
}