使用意向筛选多个动作时的默认 [英] Default when using multiple Actions in Intent-Filter
问题描述
试图神交在Android的意图和行动,并通过文档寻找。
但有一件事我一直看到的是有定义的多个动作的意图过滤器。这样,从上面的链接:
<意向滤光器>
<作用机器人:名字=android.intent.action.VIEW/>
<作用机器人:名字=android.intent.action.EDIT/>
<作用机器人:名字=android.intent.action.PICK/>
<类机器人:名字=android.intent.category.DEFAULT/>
<数据机器人:mime类型=vnd.android.cursor.dir / vnd.google.note/>
&所述; /意图滤光器>
但是,如果你调用一个活动,它是如何选择选择哪个动作?
对于这个问题,链接到例如有多个活动都包含相同的动作,android.intent.action.VIEW为例。当调用与此类似内容://com.google.provider.NotePad/notes它是如何知道要使用的活动。
但是,如果你调用一个活动,怎么样
它选择选择哪个动作?
块引用>的
意图
有动作。如果动作相匹配的意图
过滤器三者之一,并在类的匹配项,并在MIME类型相匹配,那么它会匹配意图
整体过滤和将启动活动。在换言之,多个操作(或者任何其他元素)是一个逻辑或
对于这个问题,该挂
例如有多个活动
都包含相同的动作,
android.intent.action.VIEW为
例子。
块引用>和一般有东西在
意图
过滤器来区分从下一个。
在与像调用此
内容://com.google.provider.NotePad/notes
它是如何知道哪些活动
使用?
块引用>它要求内容提供商,哟,耶 - 什么是MIME类型对于这一点,哟?。鉴于来自内容提供商的MIME类型,它可以找到任何匹配的
意图
过滤器。Trying to grok intents and actions in android and looking through the documentation. But one thing I keep seeing is an intent filter with multiple actions defined. Like this, from the above link:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.EDIT" /> <action android:name="android.intent.action.PICK" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" /> </intent-filter>
But, if you call that activity, how does it choose which action is chosen?
For that matter, that linked to example has multiple activities that all contain the same actions, "android.intent.action.VIEW" for example. When calling this with something like content://com.google.provider.NotePad/notes how does it even know which activity to use?
解决方案But, if you call that activity, how does it choose which action is chosen?
The
Intent
has an action. If that action matches one of the three in theIntent
filter, and matches on the category, and matches on the MIME type, then it will match theIntent
filter overall and will start the activity.In other words, multiple actions (or any other element) are a logical OR.
For that matter, that linked to example has multiple activities that all contain the same actions, "android.intent.action.VIEW" for example.
And generally there is stuff in the
Intent
filters to distinguish one from the next.When calling this with something like content://com.google.provider.NotePad/notes how does it even know which activity to use?
It asks the content provider, "yo, dawg -- what's the MIME type for this, yo?". Given the MIME type from the content provider, it can find any matching
Intent
filters.这篇关于使用意向筛选多个动作时的默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!