3
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
        RoleManager roleManager = context.getSystemService(RoleManager.class);
        // check if the app is having permission to be as default SMS app
        boolean isRoleAvailable = roleManager.isRoleAvailable(RoleManager.ROLE_SMS);
        if (isRoleAvailable){
            // check whether your app is already holding the default SMS app role.
            boolean isRoleHeld = roleManager.isRoleHeld(RoleManager.ROLE_SMS);
            if (isRoleHeld){
                Intent roleRequestIntent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS);
                ((AppCompatActivity)context).startActivityForResult(roleRequestIntent, ConstantsValues.REQUEST_CODES.REQUEST_RESET_SMS_HANDLER);
            }
        }
    }else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
        intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, Custom_SharedPreference.getInstance(context).getDefaultSMSPackage());
        ((AppCompatActivity)context).startActivityForResult(intent, ConstantsValues.REQUEST_CODES.REQUEST_RESET_SMS_HANDLER);
    }

This is working fine when Change SMS App to MyApp default handler but When I change MyApp to again Default SMS App then its not working and activityResult return 0 Activity.Cancle. This is happend only Android Q other Versions working fine.

Jatin Singh
  • 53
  • 1
  • 5

1 Answers1

1

In short, it's not possible to revert default SMS app.

As a work-around I decided to open the previous default SMS app using this code:

runIntent = getPackageManager().getLaunchIntentForPackage(newDefaultSmsApp);

Having the same issue, I tried various workaround, like using old method to request a change of default SMS app, however the OS doesn't care at all. Using RoleManager, when requesting to "revert" the role back to default/previous SMS app, the logs shows something like this:

2021-06-18 08:23:06.246 1770-5101/? I/ActivityTaskManager: START u0 {act=android.provider.Telephony.ACTION_CHANGE_DEFAULT cmp=com.google.android.permissioncontroller/com.android.permissioncontroller.role.ui.RequestRoleActivity (has extras)} from uid 10043
2021-06-18 08:23:06.246 1770-5101/? W/PermissionPolicyService: Action Removed: starting Intent { act=android.provider.Telephony.ACTION_CHANGE_DEFAULT cmp=com.google.android.permissioncontroller/com.android.permissioncontroller.role.ui.RequestRoleActivity (has extras) } from ccc71.sb (uid=10043)

Note the Action Removed on second line.

So in summary, it's only possible to request the role for self, but impossible to revert. A real bummer for backup apps that Google is making look bad, like so many other apps these days.

3c71
  • 4,313
  • 31
  • 43
  • I haven't used `RoleManager` yet, and have no idea what the current internal procedures are for defaults, but you might try [my answer here](https://stackoverflow.com/a/41139768). You'd have to supply your own dialog/prompt though, since that would likely be otherwise silent to the user, if it works. (I cannot vouch for the comment there; I never got a chance to test it, and then forgot it entirely.) – Mike M. Jun 18 '21 at 13:47