androidandroid-intentandroid-permissionstelephonymanagerandroid-10.0

Set my app as the default Dialler not asking options in Android 10 (Q)?


I'm currently having trouble getting my app to send the user a dialogue to set the default Dialler on API 29 but the same code is working fine below Android 10 (Q).

I test this No response from intent to prompt user to set default handler for SMS example as well but not working on mine. Then I followed https://developer.android.com/guide/topics/permissions/default-handlers but not solved my problem. Is there any special change for API level 29 or above to let the user set the default app?

Here's my working code (for below Android 10)

TelecomManager telecomManager = (TelecomManager) getSystemService(TELECOM_SERVICE);
        if (!getPackageName().equals(telecomManager.getDefaultDialerPackage())) {
            Intent intent = new Intent(ACTION_CHANGE_DEFAULT_DIALER)
                    .putExtra(EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
            startActivity(intent);
        }

What I'm getting in logcat is here

enter image description here


Solution

  • Yes, the API changed, see the note in the previous API here: https://developer.android.com/reference/android/telecom/TelecomManager#ACTION_CHANGE_DEFAULT_DIALER

    And see here for the new API: https://developer.android.com/reference/android/app/role/RoleManager

    basically, you need to do something like:

    RoleManager roleManager = (RoleManager) getSystemService(Context.ROLE_SERVICE);
    Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
    startActivityForResult(Intent, CHANGE_DEFAULT_DIALER_CODE); // you need to define CHANGE_DEFAULT_DIALER as a static final int
    

    and then you catch the response by implementing onActivityResult in your activity.