问题描述
此代码在Android 10 / Q之前有效。调用此函数时,它不再像Android 10之前的旧版本中那样弹出。
public static void promptDefaultHandler(Context context) {
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,context.getPackageName());
context.startActivity(intent);
}
2020-09-05 14:53:35.227 1818-2685 /? W / PermissionPolicyService:动作 删除:开始意图{ act = android.provider.Telephony.ACTION_CHANGE_DEFAULT cmp = com.google.android.permissioncontroller / com.android.packageinstaller.role.ui.RequestRoleActivity (有其他功能)}来自free.text.sms(uid = 10338)
解决方法
它与roleManager一起使用
RoleManager roleManager = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
roleManager = getApplicationContext().getSystemService(RoleManager.class);
if (roleManager.isRoleAvailable(RoleManager.ROLE_SMS)) {
if (roleManager.isRoleHeld(RoleManager.ROLE_SMS)) {
} else {
Intent roleRequestIntent = roleManager.createRequestRoleIntent(
RoleManager.ROLE_SMS);
startActivityForResult(roleRequestIntent,2);
}
}
}