Android的意图解析规则之一是:
An intent that contains a URI but no MIME type (neither explicit
nor inferable from the URI) passes the test only if its URI
matches the filter's URI format and the filter likewise does
not specify a MIME type.
我无法理解inferable from the URI
部分。我试着找一些例子;我认为this符合这种情况:
public void addEvent(String title, String location, Calendar begin, Calendar end) {
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(Events.TITLE, title)
.putExtra(Events.EVENT_LOCATION, location)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin)
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
<activity ...>
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<data android:mimeType="vnd.android.cursor.dir/event" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Intent有URI,但没有mime类型。 intent过滤器没有URI,但有mime类型。
有人可以解释一下如何从uri推断出mime类型吗? (必须是其他意图无法通过此过滤器)