Programmatically change the "Use default for this action"

I have a regular “Phone” and I have a new “Dialer” application. Now, if I check "Use by default for this action" and click on the "Tyler" application, then every time I press the phone button, the "Tyler" application starts automatically. But how can I change this in code?

Where is this preference saved?

And how is it displayed? Is this displayed in the android action intent line?

for example, Intent.ACTION_CALL is paired with some application, for example, the Dialer application, which will be used by default, which will be launched every time Intent.ACTION_CALL is raised ...

thank

enter image description here

+5
source share
3 answers

You cannot change the default applications using the application, but you can use the intent to go to the application settings page to set default values

Intent i = new Intent(android.provider.Settings.Aplications);
startActivity(i);

or something like this

0
source

Starting with API 21, you can use the following intent to ask the user to use the default dialer:

    Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
        .putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
    if (intent.resolveActivity(getPackageManager()) != null) {
      startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER);
    } else {
      Log.w(getLocalClassName(), "No Intent available to handle action");
    }

enter image description here

0
source
 @RequiresApi(api = Build.VERSION_CODES.M)
    private void chnagedialer() {
        TelecomManager systemService = this.getSystemService(TelecomManager.class);
        if (systemService != null && !systemService.getDefaultDialerPackage().equals("com.android.contacts")) {
            startActivity((new Intent(ACTION_CHANGE_DEFAULT_DIALER)).putExtra(EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,"com.android.contacts" ));
        }

    }
0
source

All Articles