(1)自定义字符串
public final String CUSTOME_ACTION="intent.action.CUSTOME_JIANG";//字符串可以任意
Intent intent=new Intent();
intent.setAction(ActionAttr.CUSTOME_ACTION); //注意:ActionAttr为我们创建的类,也可以使用this.CUSTOME_ACTION
(2)使用系统预定action常量
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL); //其中ACTION_CALL为Intent类的静态成员变量,可以类直接调用
//对应字符串"android.intent.action.CALL"Intent intent=new Intent();
String data="content://com.android.contacts/contacts/1";
Uri uri=Uri.parse(data);//将字符串转换为Uri
intent.setData(uri);
或者
Intent intent=new Intent();
intent.setData(Uri.parse("content://com.android.contacts/contacts/1"));(1)自定义字符串
public final String CUSTOME_CATEGORY="intent.action.CUSTOME_CATEGORY";//字符串可以任意
Intent intent=new Intent();
intent.addCategory(ActionAttr.CUSTOME_CATEGORY);
(2)使用系统预定action、category常量
以下代码实现当点击某个按钮时,通过Intent对象实现返回HOME桌面。
Intent intent=new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);//返回Home桌面 ComponentName comp=new ComponentName(ComponentAttr.this,SecondaryActivity.class); Intent intent=new Intent(); intent.setComponent( comp);//设置intent的Component属性,指定"意图"要启动组件的包和类名 注释:第一句用于创建一个ComponentName对象,来指定包名和类型-这就可以唯一地确定一个组件类。
| void |
startActivity(Intent intent)
作用:启动Activity,具体启动哪个Activity和怎么样启动由intent属性决定
|
| void |
startActivityForResult(Intent
intent, int requestCode)
作用:启动Activity,并返回一个结果。当被启动的Activity退出时,会调用 onActivityResult() 方法并向其传入一个 requestCode参数,这个 requestCode参数为非负数(>0),作用是标志是哪个Activity组件发出的"意图",需要注意的是如果 requestCode小于0时,这个方法的只能用于启动一个Activity而不能返回值了。另外,Intent的action属性设为能够返回一个结果,如果设置为
Intent.ACTION_MAIN or Intent.ACTION_VIEW,也是不能获取结果的。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
为一个指定的组件创建一个带action和data属性的意图
|
|
addCategory(String category)
Add a new category to the intent.
|
|
|
addFlags(int
flags)
Add additional flags to the intent (or with existing flags value).
|
|
|
Retrieve the general action to be performed, such as
ACTION_VIEW. |
|
|
Return the set of all categories in the intent.
|
|
|
Retrieve the concrete component associated with the intent.
|
|
|
getData()
Retrieve data this intent is operating on.
|
|
|
Retrieves a map of extended data from the intent.
|
|
|
int
|
getFlags()
Retrieve any special flags associated with this intent.
|
|
static Intent
|
This method was deprecated in API level 4. Use
parseUri(String,
int) instead. |
|
Retrieve the application package name this Intent is limited to.
|
|
|
Return the scheme portion of the intent‘s data.
|
|
|
Return the specific selector associated with this Intent.
|
|
|
Get the bounds of the sender of this intent, in screen coordinates.
|
|
|
getType()
Retrieve any explicit MIME type included in the intent.
|
|
|
boolean
|
hasCategory(String category)
Check if a category exists in the intent.
|
|
boolean
|
Returns true if an extra value is associated with the given name.
|
|
static Intent
|
makeMainActivity(ComponentName mainActivity)
Create an intent to launch the main (root) activity of a task.
|
|
static Intent
|
makeMainSelectorActivity(String selectorAction, String selectorCategory)
Make an Intent for the main activity of an application, without specifying a specific activity to run but giving a selector to find the
activity.
|
|
static Intent
|
parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
Parses(解析) the "intent" element (and its children) from XML and instantiates an Intent object.
|
|
static Intent
|
Create an intent from a URI.
|
|
Add extended data to the intent.
|
|
|
putExtra(String name, CharSequence value)
Add extended data to the intent.
|
|
|
Set the general action to be performed.
|
|
|
Convenience for calling
setComponent(ComponentName) with
the name returned by a Class object. |
|
|
setClassName(Context packageContext, String className)
Convenience for calling
setComponent(ComponentName) with
an explicit class name. |
|
|
setClassName(String packageName, String className)
Convenience for calling
setComponent(ComponentName) with
an explicit application package name and class name. |
|
|
setComponent(ComponentName component)
(Usually optional) Explicitly set the component to handle the intent.
|
|
|
Set the data this intent is operating on.
|
|
|
setFlags(int
flags)
Set special flags controlling how this intent is handled.
|
|
|
setPackage(String packageName)
(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to.
|
|
|
void
|
Set the bounds of the sender of this intent, in screen coordinates.
|
|
Set an explicit MIME data type.
|
|
|
toString()
Returns a string containing a concise(简洁), human-readable (可读)description of this object.
|
|
|
toUri(int
flags)
Convert this Intent into a String holding a URI representation of it.
|
ACTION_MAIN
//传递返回到主Activity动作ACTION_VIEW
//传递显示动作ACTION_ATTACH_DATAACTION_EDIT
//传递编辑动作ACTION_PICK
ACTION_CHOOSER
//传递选择动作ACTION_GET_CONTENTACTION_DIALACTION_CALLACTION_SENDACTION_SENDTOACTION_ANSWER
//传递接听电话动作ACTION_INSERTACTION_DELETEACTION_RUNACTION_SYNCACTION_PICK_ACTIVITYACTION_SEARCHACTION_WEB_SEARCHACTION_FACTORY_TESTEXTRA_ALARM_COUNTEXTRA_BCCEXTRA_CCEXTRA_CHANGED_COMPONENT_NAMEEXTRA_DATA_REMOVEDEXTRA_DOCK_STATEEXTRA_DOCK_STATE_HE_DESKEXTRA_DOCK_STATE_LE_DESKEXTRA_DOCK_STATE_CAREXTRA_DOCK_STATE_DESKEXTRA_DOCK_STATE_UNDOCKEDEXTRA_DONT_KILL_APPEXTRA_EMAILEXTRA_INITIAL_INTENTSEXTRA_INTENTEXTRA_KEY_EVENTEXTRA_ORIGINATING_URIEXTRA_PHONE_NUMBEREXTRA_REFERREREXTRA_REMOTE_INTENT_TOKENEXTRA_REPLACINGEXTRA_SHORTCUT_ICONEXTRA_SHORTCUT_ICON_RESOURCEEXTRA_SHORTCUT_INTENTEXTRA_STREAMEXTRA_SHORTCUT_NAMEEXTRA_SUBJECTEXTRA_TEMPLATEEXTRA_TEXTEXTRA_TITLEEXTRA_UIDgetFlags()addFlags(int)FLAG_GRANT_READ_URI_PERMISSIONFLAG_GRANT_WRITE_URI_PERMISSIONFLAG_GRANT_PERSISTABLE_URI_PERMISSIONFLAG_GRANT_PREFIX_URI_PERMISSIONFLAG_DEBUG_LOG_RESOLUTIONFLAG_FROM_BACKGROUNDFLAG_ACTIVITY_BROUGHT_TO_FRONTFLAG_ACTIVITY_CLEAR_TASKFLAG_ACTIVITY_CLEAR_TOPFLAG_ACTIVITY_CLEAR_WHEN_TASK_RESETFLAG_ACTIVITY_EXCLUDE_FROM_RECENTSFLAG_ACTIVITY_FORWARD_RESULTFLAG_ACTIVITY_LAUNCHED_FROM_HISTORYFLAG_ACTIVITY_MULTIPLE_TASKFLAG_ACTIVITY_NEW_DOCUMENTFLAG_ACTIVITY_NEW_TASKFLAG_ACTIVITY_NO_ANIMATIONFLAG_ACTIVITY_NO_HISTORYFLAG_ACTIVITY_NO_USER_ACTIONFLAG_ACTIVITY_PREVIOUS_IS_TOPFLAG_ACTIVITY_RESET_TASK_IF_NEEDEDFLAG_ACTIVITY_REORDER_TO_FRONTFLAG_ACTIVITY_SINGLE_TOPFLAG_ACTIVITY_TASK_ON_HOMEFLAG_RECEIVER_REGISTERED_ONLYAndroid笔记五.深入理解Intent和IntentFilters(一)
原文地址:http://blog.csdn.net/u012637501/article/details/41080891