Android 中的意图解析
如果我想创建自定义地址簿(它会覆盖手机的默认地址簿),并且希望它被所有应用程序使用,那么我的intent-filter?考虑到这样的第三方应用程序可能是恶意的,Android 是否允许我做这样的事情?!
而且,如果我想要另一个地址簿应用程序,我想第二个应用程序也有相同的 intent-filter
,不是吗?如果我在拨打电话时单击“联系人”按钮,框架如何决定选择哪个应用程序?换句话说,如果多个意图过滤器之间存在冲突,框架如何解决意图?
If I want to create custom address book (which overrides my phone's default address book), and if I want it to be used by all applications, what should be my intent-filter
? Does Android allow me to do such a thing considering the fact that such a third-party app could potentially be malicious?!
And, if I want to have yet another address book application, I suppose the second app also has same intent-filter
, isn't it? How does the framework decide which app to pick if I click on Contacts button when making a call? In other words, how does the framework resolve intents in case,there is a conflict between multiple intent-filters
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以替换Android平台上的任何应用程序,甚至是Home。 Android 文档解释了有关意图和意图过滤器 并且有一个名为 意图解析 的部分回答你的问题。 Intent 类的意图解析部分包含一些附加信息。
据我所知,Android 不会尝试解决冲突。它询问用户要运行哪个应用程序,并让他们选择将此 Activity 标记为此 Intent 的默认值。他们在此处提供了一个有关邮件应用程序的示例 。
You can replace any application on Android platform, even Home. Android documentation explains everything there is to know about Intents and Intent Filters and there is a section called Intent Resolution that answers your question. Intent Resolution section for Intent class has some additional information.
As far as I can tell Android doesn't try to resolve a conflict. It ask the user which application to run and gives them the choice to mark this Activity as the default for this Intent. They give an example about mail app here.
虽然 Smiljanić 先生基本上是正确的,但 Android 中没有联系人应用程序可供您替换。 Dialtacts 是支持联系人、通话记录和拨号器的应用程序。该应用程序无法替换,主要是因为拨号器无法替换。
因此,虽然您可能能够覆盖某些意图过滤器并控制某些与联系人相关的请求,但您将无法覆盖 Dialtacts 的联系人部分,这会让用户感到困惑。
While Mr. Smiljanić is basically correct, there is no Contacts application in Android for you to replace. There is Dialtacts, which is the application supporting the contacts, call log, and dialer. That application cannot be replaced, mostly because the dialer cannot be replaced.
So, while you may be able to override some intent filters and get control on some contacts-related requests, you will be unable to get the contacts portion of Dialtacts overridden, which will confuse users.