intent使用总结
2011-08-08 20:16
134 查看
1. 指定action 和type
// SIM import
Intent importIntent = new Intent(Intent.ACTION_VIEW);
importIntent.setType("vnd.android.cursor.item/sim-contact");
importIntent.setClassName("com.android.phone", "com.android.phone.SimContacts");
menu.add(0, 0, 0, R.string.importFromSim)
.setIcon(R.drawable.ic_menu_import_contact)
.setIntent(importIntent);
2. 指定action, data和type
(1)隐式查找type
示例代码:
uri: content://simcontacts/simPeople/(id)
intent = new Intent("android.intent.action.SIMEDIT",uri);
startActivity(intent);
程序会很据data中的uri去查找匹配的type(必须的)
provider中的getType()
case SIM_PEOPLE_ID:
return "vnd.android.cursor.item/sim-contact";
配置文件中的filter设定
AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.SIMEDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data 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 data) {
mData = data;
mType = null;
return this;
}
public Intent setType(String type) {
mData = null;
mType = type;
return this;
}
public Intent setDataAndType(Uri data, String type) {
mData = data;
mType = type;
return this;
}
2. 如果指定data,而type为null,则会提示找不到activity
这时需要在putExtra()中指定uri
// SIM import
Intent importIntent = new Intent(Intent.ACTION_VIEW);
importIntent.setType("vnd.android.cursor.item/sim-contact");
importIntent.setClassName("com.android.phone", "com.android.phone.SimContacts");
menu.add(0, 0, 0, R.string.importFromSim)
.setIcon(R.drawable.ic_menu_import_contact)
.setIntent(importIntent);
2. 指定action, data和type
(1)隐式查找type
示例代码:
uri: content://simcontacts/simPeople/(id)
intent = new Intent("android.intent.action.SIMEDIT",uri);
startActivity(intent);
程序会很据data中的uri去查找匹配的type(必须的)
provider中的getType()
case SIM_PEOPLE_ID:
return "vnd.android.cursor.item/sim-contact";
配置文件中的filter设定
AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.SIMEDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data 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 data) {
mData = data;
mType = null;
return this;
}
public Intent setType(String type) {
mData = null;
mType = type;
return this;
}
public Intent setDataAndType(Uri data, String type) {
mData = data;
mType = type;
return this;
}
2. 如果指定data,而type为null,则会提示找不到activity
这时需要在putExtra()中指定uri
相关文章推荐
- Intent 使用总结
- Activity之间使用intent传递大量数据带来问题总结
- Activity加载模式及Intent的FLAG使用总结
- Intent使用总结
- Intent 使用总结
- 【android中级】Android 系统应用调用,intent的使用总结
- Activity之间使用intent传递大量数据带来问题总结
- Activity之间使用intent传递大量数据带来问题总结
- Activity之间使用intent传递大量数据带来问题总结
- Activity加载模式及Intent的FLAG使用总结
- Android 系统应用调用,intent的使用总结帖
- Activity之间使用intent传递大量数据带来问题总结
- Android 系统应用调用,intent 的使用总结
- Intent及intent-filter总结与使用
- Android 系统应用调用,intent 的使用方法总结
- Android 系统应用调用,intent的使用总结帖(转自android专区)
- Android Intent使用总结
- intent使用总结
- intent方法使用总结
- 《第一行代码》第二版 学习总结31 IntentService服务基本使用