开发者

How would I go about getting the package names of the applications that can be Home on android

开发者 https://www.devze.com 2023-01-05 03:01 出处:网络
My activity gets set as the default Home by the user, but I want to be able to launch the default Home from within my activity as well.I\'ve tried hard coding the following:

My activity gets set as the default Home by the user, but I want to be able to launch the default Home from within my activity as well. I've tried hard coding the following:

Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); PackageManager pm = getPackageManager(); String packageName = "com.android.launcher"; String className = "com.android.launcher.Lau开发者_StackOverflowncher"; final ComponentName cn = new ComponentName(packageName, >className); intent.setComponent(cn);

This seems to work on my droid, but force closes on the HTC Ally. I'm thinking there's an easier way to just get a list of the apps that have the category Home and Default.

For those that have used the Home Swittcher app. I essentially want to generate that list of installed default Home activities on the phone.


Step #1: Create an Intent that launches whatever the user has for the default HOME application. In other words, do not try putting in the ComponentName.

Step #2: Call queryIntentActivities() on PackageManager to find out who all can respond to that Intent.

Step #3: If there are only two entries in the list, find out which is yours, and the other one is the platform's. If there are 3+ entries in the list, remove yours and let the user choose among the remaining options.

You could sorta combine #2 and #3 by using queryIntentActivityOptions() if you like, setting it up to filter your own Intent out of the list.

0

精彩评论

暂无评论...
验证码 换一张
取 消