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

人走茶凉 提交于 2019-12-06 04:16:06

问题


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:

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


回答1:


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




回答2:


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);


来源:https://stackoverflow.com/questions/10709779/android-home-screen-launcher-chooser-does-not-show-use-by-default-for-this-acti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!