安卓:我可以启用/禁用编程活动的意图过滤器? [英] Android: Can I enable/disable an activity's intent filter programmatically?

查看:168
本文介绍了安卓:我可以启用/禁用编程活动的意图过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要隐藏或显示,具体取决于某些运行时信息发射器我的应用程序的图标。我想还是可以通过明确的意图来运行活动,因此,禁用该活动是不是一个好的选择(我甚至不知道是否它会工作,我还没有尝试过,但我想这会)。所以,我可以禁用意图过滤器?

I need to hide or show my app's icon in the launcher depending on some runtime information. I'd like to still be able to run the activity by an explicit intent, so disabling the activity isn't a good option (I don't even know for sure if it will work, I haven't tried it yet, but I guess it will). So, can I disable an intent filter?

推荐答案

您可以直接这样做,但是你可以创建一个的activity别名你的的Andr​​oidManifest.xml 与有问题的意图过滤器,然后启用或禁用使用别名<一个href="http://developer.android.com/reference/android/content/pm/PackageManager.html#setComponentEnabledSetting%28android.content.ComponentName,%20int,%20int%29"><$c$c>PackageManager#setComponentEnabledSetting(),让你的另一意图过滤器在活动的主副本,以便他们将不会受到影响。

You can't do this directly, but you can create an activity alias in your AndroidManifest.xml with the intent filter in question, and then enable or disable the alias using PackageManager#setComponentEnabledSetting(), leaving your other intent filters in the main copy of the Activity so they won't be affected.

这篇关于安卓:我可以启用/禁用编程活动的意图过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆