Launch Home Chooser Dialog
After long time digging in Android source code, I’ve found a way to pop-up the Home Chooser dialog.
Above is how it displays on my phone. Anyway, here the way how to do it:
static final String HOME_CHOOSER_PACKAGE_NAME = "android"; static final String HOME_CHOOSER_CLASS_NAME = "com.android.internal.app.ResolverActivity"; private void launchHomeChooser() { Intent i = new Intent(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_HOME); i.setClassName(HOME_CHOOSER_PACKAGE_NAME, HOME_CHOOSER_CLASS_NAME); startActivity(i); }
If you search over Internet, there might be many other ways to create a similar Home Chooser dialog, however, it takes lots of coding and customization. Well, I prefer to call the framework one.
One more thing, it works on my device Galaxy SII, running ROM Resurrection Remix v2.5.3 (Android ICS v4.0.4); so I’m not really certain that it would work for every device, but it should work for most of devices then. It runs fine on Android 2.3.x devices, too.
Cheers,
Pete Houston
Get Default Launcher on Device
A simple snippet to get default launcher on device, which is checked “Use by default for this action” on Launcher selection dialog.
public static ApplicationInfo getDefaultLauncher(Context context) { // first query all installed launcher ArrayList<ApplicationInfo> listAppInfo = getAllLaunchers(context); // the default launcher queried being stored here ArrayList<ComponentName> listDefault = new ArrayList<ComponentName>(); // create list IntentFilter for Launcher apps final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN); filter.addCategory(Intent.CATEGORY_HOME); filter.addCategory(Intent.CATEGORY_DEFAULT); ArrayList<IntentFilter> listFilters = new ArrayList<IntentFilter>(); listFilters.add(filter); // query default launcher context.getPackageManager().getPreferredActivities(listFilters, listDefault, null); // check if default launcher if(listDefault.size() > 0) { for(ComponentName name: listDefault) { for(ApplicationInfo info: listAppInfo) { if(name.getPackageName().equals(info.packageName)) { // found yeah! return info; } } } } // not found any, no launcher set Default return null; }
Refer to my previous post to get all install Launchers on device.
Cheers,
Pete Houston
Query all installed Launcher Applications
The tip for making this happen is that all launchers register these two categories in Manifest
+ CATEGORY_HOME
+ CATEGORY_DEFAULT
and this is my snippet to query ’em all.
public static ArrayList<ApplicationInfo> getAllLaunchers(Context context) { // create new intent final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); // all launchers register these two categories mainIntent.addCategory(Intent.CATEGORY_HOME); mainIntent.addCategory(Intent.CATEGORY_DEFAULT); // query normally final ArrayList<ResolveInfo> pkgAppsList = (ArrayList<ResolveInfo>) context.getPackageManager().queryIntentActivities( mainIntent, 0); // you can return 'pkgAppsList' // anyway, I need the following information, // so I just query what I need ArrayList<ApplicationInfo> listAppInfo = new ArrayList<ApplicationInfo>(); for(ResolveInfo info: pkgAppsList) { listAppInfo.add(info.activityInfo.applicationInfo); } // return return listAppInfo; }
There you go, gotta do something with it.
Enjoy and have fun!
Cheers,
Pete Houston