1. 指定act
ion 和type
// SIM imp ort
Intent imp ortIntent = new Intent(Intent.ACT
ION_VIEW);
imp ortIntent.setType("vnd.android.cursor.item/sim-contact");
imp ortIntent.setClassName("com.android.phone", "com.android.phone.SimContacts");
menu.add(0, 0, 0, R.string.imp ortFromSim)
.setIcon(R.drawable.ic_menu_imp ort_contact)
.setIntent(imp ortIntent);
2. 指定act ion, da
ta和type
(1)隐式查找type
示例代码:
uri: content://simcontacts/simPeople/(id)
intent = new Intent("android.intent.act ion.SIMEDIT",uri);
startActivity(intent);
程序会很据da ta中的uri去查找匹配的type(必须的)
provider中的getType()
case SIM_PEOPLE_ID:
return "vnd.android.cursor.item/sim-contact";
配置文件中的filter设定
AndroidManifest.xml
<intent-filter>
<act ion android:name="android.intent.act
ion.SIMEDIT" />
<category android:name="android.intent.category.DEFAULT" />
<da ta android:mimeType="vnd.android.cursor.item/sim-contact" />
</intent-filter>
也可以自己设定type,但只能使用 setDataAndType()
3. 其他设定intent的属性方式
Intent setComponent(ComponentName component)
Intent setClassName(Context packageContext, String className)
Intent setClassName(String packageName, String className)
Intent setClass(Context packageContext, Class<?> cls)
注:
1. intent的实现代码
public Intent setData(Uri da ta) {
mData = da ta;
mType = null;
return this;
}
public Intent setType(String type) {
mData = null;
mType = type;
return this;
}
public Intent setDataAndType(Uri da ta, String type) {
mData = da ta;
mType = type;
return this;
}
2. 如果指定da ta,而type为null,则会提示找不到activity
这时需要在putExtra()中指定uri
// SIM imp
Intent imp
imp
imp
menu.add(0, 0, 0, R.string.imp
.setIcon(R.drawable.ic_menu_imp
.setIntent(imp
2. 指定act
(1)隐式查找type
示例代码:
uri: content://simcontacts/simPeople/(id)
intent = new Intent("android.intent.act
startActivity(intent);
程序会很据da
provider中的getType()
case SIM_PEOPLE_ID:
return "vnd.android.cursor.item/sim-contact";
配置文件中的filter设定
AndroidManifest.xml
<intent-filter>
<act
<category android:name="android.intent.category.DEFAULT" />
<da
</intent-filter>
也可以自己设定type,但只能使用 setDataAndType()
3. 其他设定intent的属性方式
Intent setComponent(ComponentName component)
Intent setClassName(Context packageContext, String className)
Intent setClassName(String packageName, String className)
Intent setClass(Context packageContext, Class<?> cls)
注:
1. intent的实现代码
public Intent setData(Uri da
mData = da
mType = null;
return this;
}
public Intent setType(String type) {
mData = null;
mType = type;
return this;
}
public Intent setDataAndType(Uri da
mData = da
mType = type;
return this;
}
2. 如果指定da
这时需要在putExtra()中指定uri