重新提示选择默认活动

发布于 2024-09-28 08:06:28 字数 177 浏览 4 评论 0原文

有没有办法重新提示用户为意图选择默认活动?例如,用户选择他的默认家庭 apk,我希望他再次重新考虑他的选择。

我知道如何在 2.1 及之前版本上执行此操作,但现在有办法在 2.2 上执行此操作吗?

著名的 Home Switcher 做了类似的事情,但由于 google 团队的原因,它不再在 2.2 上运行

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.2?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宁愿没拥抱 2024-10-05 08:06:28

这就是我表示活动选择对话框的方式:
它为“HOME”应用程序启动 android 默认的 ResolverActivity。

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

上面的代码适用于我的 2.2 版平板电脑。
执行时,它会显示“完成操作:”对话框,列表中包含所有可能的家庭应用程序。


一种检测当前默认设置的方法,您可以询问所有首选活动。列表“filters”和“comps”包含调用 .getPreferredActivities(...) 时的数据。

filters - 包含意图过滤器数据,您可以查询它是什么类型的数据。

comps - 包含如果意图过滤器匹配则将调用的组件

这样您可以检查您的应用程序是否是用户首选的当前“主”应用程序集。

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

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);
网名女生简单气质 2024-10-05 08:06:28

例如,用户选择了他的默认家庭 apk,我希望他再次重新考虑他的选择。

除非您的应用程序是首选应用程序,否则这种情况已不再可能。然后,我认为您可以使用 clearPackagePreferredActivities() 将自己从首选中删除。

换句话说,欢迎您影响自己的应用程序,但不欢迎您影响其他应用程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文