在manifest文件中activity會有這樣的屬性
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/person" />
<data android:mimeType="vnd.android.cursor.dir/contact" />
</intent-filter>
ContentProvider 的 getType(Uri uri) 方法,返回的就是其中對應的mimetype值,匹配manifest的話,才能啓動activity。
這個方法什麼時候調用呢?
startActivity(intent)
Instrumentation.execStartActivity()
Intent.resolveTypeIfNeeded()
Intent.java
public String resolveTypeIfNeeded(ContentResolver resolver) {
if (mComponent != null) {
return mType;
}
return resolveType(resolver);
}
public String resolveType(ContentResolver resolver) {
if (mType != null) {
return mType;
}
if (mData != null) {
if ("content".equals(mData.getScheme())) {
return resolver.getType(mData);
}
}
return null;
}
如果
1、startActivity(intent)的intent 時隱式的(即沒有直接設置類名)
2、並且沒有設置type
3、並且設置了uri(如調用了setData(uri))
那麼就會調用到
ContentResolver.getType(mData)
也就調用到了 ContentProvider 的 getType(Uri uri)。