Android 10-提示用户更改默认短信无效

问题描述

代码在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);
}

logcat中有一个错误,我不清楚这是什么错误

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);
            }
        }
    }

源-https://stackoverflow.com/a/60372137/1114170