Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically change the "Use by default for this action"

Tags:

android

I have the normal 'Phone' dialer and I have new 'Dialer' app. Now if I check the "Use by default for this action" and click on the 'Dialer' app then every time when I press the phone button the 'Dialer' app will be started automatically. But how can I change this in code ?

Where this preference is stored ?

And how is this mapped ? is this is mapped by an android action intent string ?

for example the Intent.ACTION_CALL is paired with some application for example the 'Dialer' app to be the default app that will be started every time the Intent.ACTION_CALL it is raised...

Thanks

enter image description here

like image 689
Lukap Avatar asked Nov 26 '22 04:11

Lukap


1 Answers

Starting from API 21 you can use next intent to ask user to be a 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

like image 84
Gaket Avatar answered Jan 17 '23 09:01

Gaket