1

I was able to set the app as a default messaging app with the below code

Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
            intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
                    getPackageName());
            startActivityForResult(intent, SET_AS_DEFAULT_INTENT);

But this works only on API <= 28 (Android 9 or below)

But this is not working on Android 10 or above.

Am I missing something? I heard about using a role manager but it is not working for me.

RoleManager roleManager = 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, SET_AS_DEFAULT_INTENT);
                }
            }
Nithis Kumar
  • 278
  • 2
  • 5
  • 21
  • So `RoleManager` is working for you or not? – Saurabh Thorat Jun 24 '20 at 14:19
  • what is the question here? – Shalu T D Jun 24 '20 at 14:20
  • Which specific versions are you having the problem on? API level 28 is Pie, Android 9, so I'm not sure exactly what you mean by these two statements: "But this works only on API <= 28 (Android 8 or below)", "But this is not working on Android 9 or above.", especially since the title specifies Android Q. Also, what happens when it doesn't work? Is it crashing? – Mike M. Jun 25 '20 at 02:50
  • @MikeM. sorry for the confusion I edited that now. The problem is with Android 10 and above only. It works on Android 9 and below. – Nithis Kumar Jun 25 '20 at 09:10
  • @SaurabhThorat Oops, I made a lot of typo in the question and I corrected them now, sorry for that. – Nithis Kumar Jun 25 '20 at 09:13
  • OK, yeah, if you're targeting 30, then you need to use the `RoleManager` method instead. Your code works for me, however, in my quick test project. Is your app listed in the available default app list on the Q device? – Mike M. Jun 25 '20 at 09:48
  • Yes, it is showing in the list but no dialog appears inside of the app to select. – Nithis Kumar Jun 25 '20 at 09:59
  • Hmm, that's odd. Here's what I get: https://i.stack.imgur.com/LoszU.jpg. At this point, all I could suggest is to make sure that it's actually getting to the `startActivityForResult()` call. That is, make sure that those `if` conditions are true. I'll see if I can figure out how to get the behavior you're observing. – Mike M. Jun 25 '20 at 10:05
  • Did you added anything on the manifest? – Nithis Kumar Jun 25 '20 at 10:16
  • Yeah, just what's needed for the app to qualify as an eligible default: https://stackoverflow.com/a/30133663. – Mike M. Jun 25 '20 at 10:18
  • Voila, added those things in AndroidManifest and worked. Thanks a lot, mate. – Nithis Kumar Jun 25 '20 at 10:21
  • 1
    I literally just started a new project, made sure the `targetSdkVersion` is 30, and copied/pasted that linked manifest, and your code into it. – Mike M. Jun 25 '20 at 10:21
  • 1
    Oh, was that it? Just missing some manifest entries? – Mike M. Jun 25 '20 at 10:22
  • I really appreciate your help. Thanks again. – Nithis Kumar Jun 25 '20 at 10:22
  • No problem. Glad you got it working. Cheers! – Mike M. Jun 25 '20 at 10:22

0 Answers0