如何解决Android 电信系统角色管理器
我正在尝试实现调用应用程序。对于 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>
对于 API
这里是我在 TelecomManager 注册我的东西的地方。
// 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();
}
所以我们在这里看到我将 ROLE_SERVICE 和 ROLE_DIALER 用于我的 RoleManager。 但是,我从来没有得到提示。从这里阅读它:
https://proandroiddev.com/android-q-to-the-res-q-9a88733aedda
我看到它说:
为了让 RoleManager 正确解析请求,您的清单必须指定类别、权限或其他意图过滤器,以便正确持有角色。如果您不这样做,请求将被自动取消
但即使在官方 Android 文档中,我也没有看到角色 ROLE_DIALER 的特定类别、权限或其他意图过滤器的确切列表。
https://developer.android.com/reference/androidx/core/role/RoleManagerCompat#ROLE_DIALER
我认为 API 之间的区别在于较旧的 API 使用 TelecomManager 的 Intent,而较新的 API 使用这个新的 RoleManager。我想就是这样,但也许我离题了。
总之……为什么这对 API
解决方法
<action android:name="android.intent.category.DEFAULT" />
应该是
<category android:name="android.intent.category.DEFAULT" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。