java 如何在android中以编程方式添加或删除意图过滤器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4862607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add or remove intent filter programmatically in android?
提问by dhaval
Is it possible to remove intent filters from activity based on user preference? Say dial intent filter is added and then at later point of time user decides the application should not handle dial.
是否可以根据用户偏好从活动中删除意图过滤器?假设添加了拨号意图过滤器,然后在稍后的时间点用户决定应用程序不应处理拨号。
Edit: Removed add part in question description
编辑:删除了问题描述中的添加部分
回答by Will Tate
No, it seems they are static.
不,它们似乎是静态的。
An intent filter is an instance of the IntentFilter class. However, since the Android system must know about the capabilities of a component before it can launch that component, intent filters are generally not set up in Java code, but in the application's manifest file (AndroidManifest.xml) as elements.
意图过滤器是 IntentFilter 类的一个实例。但是,由于 Android 系统在启动该组件之前必须了解该组件的功能,因此 Intent 过滤器通常不在 Java 代码中设置,而是在应用程序的清单文件 (AndroidManifest.xml) 中作为元素设置。
Source: http://developer.android.com/guide/topics/intents/intents-filters.html#ifs
来源:http: //developer.android.com/guide/topics/intents/intents-filters.html#ifs
回答by scottyab
I thought maybe you could enable/disable via the Package manager, but despite have a GET_INTENT_FILTERS flag in the PackageManager, it seems it's not supported.
我想也许你可以通过包管理器启用/禁用,但尽管PackageManager 中有一个 GET_INTENT_FILTERS 标志,但它似乎不受支持。