How to open Home Launcher List settings screen programmatically in Android using Intent

爷,独闯天下 提交于 2019-12-21 19:19:33

问题


I am looking for a way to open a Launcher list screen in Home option in system Settings using Intent.

main system Settings >> Home >> Launcher List.

I need to open this Launcher list screen using Intent. If anyone could point me in the right direction I would really appreciate it. Thanks much.


回答1:


To bring up the home screen settings page, call the Settings.ACTION_HOME_SETTINGS intent. However this is ONLY supported in API 21 and above.

API 20 and below need to call the Settings.ACTION_SETTINGS intent, and the user must navigate the rest of the way. (Preferably with instructions before hand)

To provide the best intent when available, use the following code. This will open the home settings directly on API 21 and above, else it will open the settings page on API 20 and below.

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    final Intent intent = new Intent(Settings.ACTION_HOME_SETTINGS);
    startActivity(intent);
}
else {
    final Intent intent = new Intent(Settings.ACTION_SETTINGS);
    startActivity(intent);
}



回答2:


For those who want to open the default launcher apps settings activity you could use the following code

  PackageManager localPackageManager = getPackageManager();
  Intent intent = new Intent("android.intent.action.MAIN");
  intent.addCategory("android.intent.category.HOME"); 
  final String currentLauncherPackageName = localPackageManager.resolveActivity(intent,
            PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;

  Intent intent = new Intent();
  intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  Uri uri = Uri.fromParts("package", currentLauncherPackageName, null);
  intent.setData(uri);
  startActivity(intent);

In case you need to instruct the user to disable default launcher app before selecting your app




回答3:


Intent intent = new Intent(Settings.ACTION_HOME_SETTINGS);
startActivity(intent);


来源:https://stackoverflow.com/questions/37149695/how-to-open-home-launcher-list-settings-screen-programmatically-in-android-using

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