简体   繁体   中英

Android home-screen/launcher chooser does not show 'use by default for this action' option

I am trying to launch the Home-screen/Launcher chooser dialog programmatically by using the following intent:

Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(Intent.createChooser(i, "Set My HomeScreen as default"));

But unfortunately the dialog that appears with the list of installed home-screen launchers does not have the Use by default for this action option at the bottom of the dialog. The following image shows how it looks:

主屏幕

Interestingly after choosing my home-screen from the above chooser dialog, if I press home button from my that screen then Android automatically shows up a similar dialog which in fact has the Use by default for this option at the bottom of the dialog. Here is how it looks:

HomeScreen选择器

I am pretty clueless about what's wrong with the above code, it must be some silly mistake that I am not able to spot myself.

if anyone of can shed some light, then it would be of great help.

Thanks

createChooser() does not produce a "default for this action" checkbox. If you'd like the checkbox, instead pass an intent to startActivityForResult()

This is how you do it on ICS:

final PackageManager packageManager = this.getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
startActivity(selector);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM