开发者

re-prompt to choose default activity

is there a way to reprompt the user to choose a default activity for an intent? For example, user selects his default home apk and I want him to reconsider his choice once again.

I know how to do that on 2.1 and before, but is there a way to do that now on 2.开发者_JAVA百科2?

Famous Home Switcher, which did similar thing, does not work on 2.2 anymore thanks to google team


This is how I represent the Activity selection dialog: It start the android default ResolverActivity for "HOME" Applications.

Intent selector = new Intent("android.intent.action.MAIN");
selector.addCategory("android.intent.category.HOME");
selector.setComponent(new ComponentName("android", "com.android.internal.app.ResolverActivity"));

startActivity(selector);

The above code is working for my 2.2 enabled tablets. When executed, it displays the "Complete Actions with:" dialog with all possible Home applications in the list.


A way to detect which is currently set by default you could ask for all preferred activities. The lists "filters" and "comps" contain the data when calling .getPreferredActivities(...).

filters - contains the intent filter data, which you could query what type of data it is.

comps - contians the component which would be called if the intent filter matches

This way you could check if your application is the current "home" application set as preferred by the user.

List<IntentFilter> filters = new ArrayList<IntentFilter>();
List<ComponentName> comps= new ArrayList<ComponentName>();
getPackageManager().getPreferredActivities(filters, comps, null);


For example, user selects his default home apk and I want him to reconsider his choice once again.

That is no longer possible, unless your app is the preferred one. Then, I think you can use clearPackagePreferredActivities() to remove yourself as the preferred choice.

In other words, you are welcome to affect your own app, but you are not welcome to affect other apps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜