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

被折叠的 条评论
为什么被折叠?



