Intent

跳转的方式:


Intent intent = new Intent();
//添加意图的动作
intent.setAction(Intent.ACTION_CALL);
//添加意图的数据
//url: 统一资源标识符  uri: 统一资源定位符
intent.setData(Uri.parse("tel:"+number));
//实现这个意图
startActivity(intent);


通过action实现我们的跳转,  设置数据 data  来设置我们传递的数据。



Intent

extends Object
implements Parcelable Cloneable
java.lang.Object
   ↳android.content.Intent

An intent is an abstract description of an operation to be performed. It can be used withstartActivity to launch anActivity,broadcastIntent to send it to any interested BroadcastReceiver components, andstartService(Intent) orbindService(Intent, ServiceConnection, int) to communicate with a background Service

一个intent就是一个执行动作的说明,

它的作用可以 开启一个activity  或者发送广播信息  还有就是可以开启或者绑定服务。

主要用在activity之间  


Intent Structure

intnet的结构:

action -- The general action to be performed, such asACTION_VIEW,ACTION_EDIT,ACTION_MAIN, etc.

设置动作  上面的是系统的。

data -- The data to operate on, such as a person record in the contacts database, expressed as aUri.


  • ACTION_VIEWcontent://contacts/people/1 -- Display information about the person whose identifier is "1".

  • ACTION_DIALcontent://contacts/people/1 -- Display the phone dialer with the person filled in.

  • ACTION_VIEWtel:123 -- Display the phone dialer with the given number filled in. Note how the VIEW action does what what is considered the most reasonable thing for a particular URI.

  • ACTION_DIALtel:123 -- Display the phone dialer with the given number filled in.

  • ACTION_EDITcontent://contacts/people/1 -- Edit information about the person whose identifier is "1".

  • ACTION_VIEWcontent://contacts/people/ -- Display a list of people, which the user can browse through. This example is a typical top-level entry into the Contacts application, showing you the list of people. Selecting a particular person to view would result in a new intent { ACTION_VIEWcontent://contacts/N } being used to start an activity to display that person.


category -- Gives additional information about the action to execute.

For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application,


type -- Specifies an explicit type (a MIME type) of the intent data.

Normally the type is inferred from the data itself. By setting this attribute, you disable that evaluation and force an explicit type.


component -- Specifies an explicit name of a component class to use for the intent.


extras -- This is a Bundle of any additional information. This can be used to provide extended information to the component.


ACTION_MAIN with categoryCATEGORY_HOME -- Launch the home screen.


Explicit Intents have specified a component (viasetComponent(ComponentName) orsetClass(Context, Class)), which provides the exact class to be run.


Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.


Standard Activity Actions

These are the current standard actions that Intent defines for launching activities (usually through startActivity(Intent). The most important, and by far most frequently used, are ACTION_MAIN and ACTION_EDIT.

Standard Broadcast Actions

These are the current standard actions that Intent defines for receiving broadcasts (usually through registerReceiver(BroadcastReceiver, IntentFilter) or a <receiver> tag in a manifest).

Standard Categories

These are the current standard categories that can be used to further clarify an Intent via addCategory(String).

Standard Extra Data

These are the current standard fields that can be used as extra data via putExtra(String, Bundle).


Intent()

Create an empty intent.

Intent( Intent o)

Copy constructor.

Intent( String action)

Create an intent with a given action.

Intent( String action, Uri uri)
Create an intent with a given action and for a given data url.

Intent( Context packageContext, Class<?> cls)

Create an intent for a specific component.
Parameters
packageContextA Context of the application package implementing this class.
clsThe component class that is to be used for the intent.



Intent( String action, Uri uri, Context packageContext, Class<?> cls)

Create an intent for a specific component with a specified action and data.

Parameters
actionThe Intent action, such as ACTION_VIEW.
uriThe Intent data URI.
packageContextA Context of the application package implementing this class.
clsThe component class that is to be used for the intent.




addCategory( String category)

Add a new category to the intent.

Parameters
categoryThe desired category. This can be either one of the predefined Intent categories, or a custom category in your own namespace.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.


addFlags(int flags)

Add additional flags to the intent (or with existing flags value).

Parameters
flagsThe new flags to set.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.


getAction()

Retrieve the general action to be performed, such as ACTION_VIEW.


         public boolean[] getBooleanArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no boolean array value was found.
public boolean getBooleanExtra (String name, boolean defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra() or the default value if none was found.
public Bundle getBundleExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no Bundle value was found.
public byte[] getByteArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no byte array value was found.
public byte getByteExtra (String name, byte defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra() or the default value if none was found.
public Set<String> getCategories ()
Added in API level 1

Return the set of all categories in the intent. If there are no categories, returns NULL.

Returns
  • The set of categories you can examine. Do not modify!
public char[] getCharArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no char array value was found.
public char getCharExtra (String name, char defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra() or the default value if none was found.
public CharSequence[] getCharSequenceArrayExtra (String name)
Added in API level 8

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no CharSequence array value was found.
public ArrayList<CharSequence> getCharSequenceArrayListExtra (String name)
Added in API level 8

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no ArrayList value was found.
public CharSequence getCharSequenceExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no CharSequence value was found.
public ClipData getClipData ()
Added in API level 16

Return the ClipData associated with this Intent. If there is none, returns null. See setClipData(ClipData) for more information.

public ComponentName getComponent ()
Added in API level 1

Retrieve the concrete component associated with the intent. When receiving an intent, this is the component that was found to best handle it (that is, yourself) and will always be non-null; in all other cases it will be null unless explicitly set.

Returns
  • The name of the application component to handle the intent.
public Uri getData ()
Added in API level 1

Retrieve data this intent is operating on. This URI specifies the name of the data; often it uses the content: scheme, specifying data in a content provider. Other schemes may be handled by specific activities, such as http: by the web browser.

Returns
  • The URI of the data this intent is targeting or null.
public String getDataString ()
Added in API level 1

The same as getData(), but returns the URI as an encoded String.

public double[] getDoubleArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no double array value was found.
public double getDoubleExtra (String name, double defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra() or the default value if none was found.
public Bundle getExtras ()
Added in API level 1

Retrieves a map of extended data from the intent.

Returns
  • the map of all extras previously added with putExtra(), or null if none have been added.
public int getFlags ()
Added in API level 1

Retrieve any special flags associated with this intent. You will normally just set them with setFlags(int) and let the system take the appropriate action with them.

Returns
  • int The currently set flags.
See Also
public float[] getFloatArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no float array value was found.
public float getFloatExtra (String name, float defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra(), or the default value if no such item is present
public int[] getIntArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no int array value was found.
public int getIntExtra (String name, int defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra() or the default value if none was found.
public ArrayList<Integer> getIntegerArrayListExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no ArrayList value was found.
public static Intent getIntent (String uri)
Added in API level 1

This method was deprecated in API level 4.
Use parseUri(String, int) instead.

Call parseUri(String, int) with 0 flags.

public static Intent getIntentOld (String uri)
Added in API level 1
public long[] getLongArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no long array value was found.
public long getLongExtra (String name, long defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra() or the default value if none was found.
public String getPackage ()
Added in API level 4

Retrieve the application package name this Intent is limited to. When resolving an Intent, if non-null this limits the resolution to only components in the given application package.

Returns
  • The name of the application package for the Intent.
public Parcelable[] getParcelableArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no Parcelable[] value was found.
public ArrayList<T> getParcelableArrayListExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no ArrayList value was found.
public T getParcelableExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no Parcelable value was found.

         public Serializable getSerializableExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no Serializable value was found.
public short[] getShortArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no short array value was found.
public short getShortExtra (String name, short defaultValue)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
defaultValuethe value to be returned if no value of the desired type is stored with the given name.
Returns
  • the value of an item that previously added with putExtra() or the default value if none was found.

         public String[] getStringArrayExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no String array value was found.
public ArrayList<String> getStringArrayListExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no ArrayList value was found.
public String getStringExtra (String name)
Added in API level 1

Retrieve extended data from the intent.

Parameters
nameThe name of the desired item.
Returns
  • the value of an item that previously added with putExtra() or null if no String value was found.

         public static Intent parseIntent (Resources resources, XmlPullParser parser, AttributeSet attrs)
Added in API level 1

Parses the "intent" element (and its children) from XML and instantiates an Intent object. The given XML parser should be located at the tag where parsing should start (often named "intent"), from which the basic action, data, type, and package and class name will be retrieved. The function will then parse in to any child elements, looking for tags to add categories and to attach extra data to the intent.

Parameters
resourcesThe Resources to use when inflating resources.
parserThe XML parser pointing at an "intent" tag.
attrsThe AttributeSet interface for retrieving extended attribute data at the current parser location.
Returns
  • An Intent object matching the XML data.
Throws
XmlPullParserExceptionIf there was an XML parsing error.
IOExceptionIf there was an I/O error.
public static Intent parseUri (String uri, int flags)
Added in API level 4

Create an intent from a URI. This URI may encode the action, category, and other intent fields, if it was returned by toUri(int). If the Intent was not generate by toUri(), its data will be the entire URI and its action will be ACTION_VIEW.

The URI given here must not be relative -- that is, it must include the scheme and full path.

Parameters
uriThe URI to turn into an Intent.
flagsAdditional processing flags. Either 0 or URI_INTENT_SCHEME.
Returns
  • Intent The newly created Intent object.
Throws
URISyntaxExceptionThrows URISyntaxError if the basic URI syntax it bad (as parsed by the Uri class) or the Intent data within the URI is invalid.
See Also
public Intent putCharSequenceArrayListExtra (String name, ArrayList<CharSequence> value)
Added in API level 8

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe ArrayList data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, double[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe double array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, int value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe integer data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, CharSequence value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe CharSequence data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, char value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe char data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, Bundle value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe Bundle data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, Parcelable[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe Parcelable[] data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, Serializable value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe Serializable data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, int[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe int array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, float value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe float data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, byte[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe byte array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, long[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe byte array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, Parcelable value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe Parcelable data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, float[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe float array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, long value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe long data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, String[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe String array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, boolean value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe boolean data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, boolean[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe boolean array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, short value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe short data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, double value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe double data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, short[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe short array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, String value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe String data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, byte value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe byte data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, char[] value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe char array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtra (String name, CharSequence[] value)
Added in API level 8

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe CharSequence array data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putExtras (Intent src)
Added in API level 1

Copy all extras in 'src' in to this intent.

Parameters
srcContains the extras to copy.
public Intent putExtras (Bundle extras)
Added in API level 1

Add a set of extended data to the intent. The keys must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
extrasThe Bundle of extras to add to this intent.
public Intent putIntegerArrayListExtra (String name, ArrayList<Integer> value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe ArrayList data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putParcelableArrayListExtra (String name, ArrayList<? extends Parcelable> value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe ArrayList data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent putStringArrayListExtra (String name, ArrayList<String> value)
Added in API level 1

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Parameters
nameThe name of the extra data, with package prefix.
valueThe ArrayList data value.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public void readFromParcel (Parcel in)
Added in API level 1

public void removeCategory (String category)
Added in API level 1

Remove a category from an intent.

Parameters
categoryThe category to remove.
public void removeExtra (String name)
Added in API level 1

Remove extended data from the intent.

public Intent replaceExtras (Bundle extras)
Added in API level 3

Completely replace the extras in the Intent with the given Bundle of extras.

Parameters
extrasThe new set of extras in the Intent, or null to erase all extras.
public Intent replaceExtras (Intent src)
Added in API level 3

Completely replace the extras in the Intent with the extras in the given Intent.

Parameters
srcThe exact extras contained in this Intent are copied into the target intent, replacing any that were previously there.
public ComponentName resolveActivity (PackageManager pm)
Added in API level 1

Return the Activity component that should be used to handle this intent. The appropriate component is determined based on the information in the intent, evaluated as follows:

If getComponent() returns an explicit class, that is returned without any further consideration.

The activity must handle the CATEGORY_DEFAULT Intent category to be considered.

If getAction() is non-NULL, the activity must handle this action.

If resolveType(ContentResolver) returns non-NULL, the activity must handle this type.

If addCategory(String) has added any categories, the activity must handle ALL of the categories specified.

If getPackage() is non-NULL, only activity components in that application package will be considered.

If there are no activities that satisfy all of these conditions, a null string is returned.

If multiple activities are found to satisfy the intent, the one with the highest priority will be used. If there are multiple activities with the same priority, the system will either pick the best activity based on user preference, or resolve to a system class that will allow the user to pick an activity and forward from there.

This method is implemented simply by calling resolveActivity(Intent, int) with the "defaultOnly" parameter true.

This API is called for you as part of starting an activity from an intent. You do not normally need to call it yourself.

Parameters
pmThe package manager with which to resolve the Intent.
Returns
  • Name of the component implementing an activity that can display the intent.
public ActivityInfo resolveActivityInfo (PackageManager pm, int flags)
Added in API level 1

Resolve the Intent into an ActivityInfo describing the activity that should execute the intent. Resolution follows the same rules as described for resolveActivity(PackageManager), but you get back the completely information about the resolved activity instead of just its class name.

Parameters
pmThe package manager with which to resolve the Intent.
flagsAddition information to retrieve as per PackageManager.getActivityInfo().
Returns
  • PackageManager.ActivityInfo
public String resolveType (ContentResolver resolver)
Added in API level 1

Return the MIME data type of this intent. If the type field is explicitly set, that is simply returned. Otherwise, if the data is set, the type of that data is returned. If neither fields are set, a null is returned.

Parameters
resolverA ContentResolver that can be used to determine the MIME type of the intent's data.
Returns
  • The MIME type of this intent.
public String resolveType (Context context)
Added in API level 1

Return the MIME data type of this intent. If the type field is explicitly set, that is simply returned. Otherwise, if the data is set, the type of that data is returned. If neither fields are set, a null is returned.

Returns
  • The MIME type of this intent.

         public Intent setAction (String action)
Added in API level 1

Set the general action to be performed.

Parameters
actionAn action name, such as ACTION_VIEW. Application-specific actions should be prefixed with the vendor's package name.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
See Also
public Intent setClass (Context packageContext, Class<?> cls)
Added in API level 1

Convenience for calling setComponent(ComponentName) with the name returned by a Class object.

Parameters
packageContextA Context of the application package implementing this class.
clsThe class name to set, equivalent to setClassName(context, cls.getName()).
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent setClassName (Context packageContext, String className)
Added in API level 1

Convenience for calling setComponent(ComponentName) with an explicit class name.

Parameters
packageContextA Context of the application package implementing this class.
classNameThe name of a class inside of the application package that will be used as the component for this Intent.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent setClassName (String packageName, String className)
Added in API level 1

Convenience for calling setComponent(ComponentName) with an explicit application package name and class name.

Parameters
packageNameThe name of the package implementing the desired component.
classNameThe name of a class inside of the application package that will be used as the component for this Intent.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public void setClipData (ClipData clip)
Added in API level 16

Set a ClipData associated with this Intent. This replaces any previously set ClipData.

The ClipData in an intent is not used for Intent matching or other such operations. Semantically it is like extras, used to transmit additional data with the Intent. The main feature of using this over the extras for data is that FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION will operate on any URI items included in the clip data. This is useful, in particular, if you want to transmit an Intent containing multiple content: URIs for which the recipient may not have global permission to access the content provider.

If the ClipData contains items that are themselves Intents, any grant flags in those Intents will be ignored. Only the top-level flags of the main Intent are respected, and will be applied to all Uri or Intent items in the clip (or sub-items of the clip).

The MIME type, label, and icon in the ClipData object are not directly used by Intent. Applications should generally rely on the MIME type of the Intent itself, not what it may find in the ClipData. A common practice is to construct a ClipData for use with an Intent with a MIME type of "*\/*".

Parameters
clipThe new clip to set. May be null to clear the current clip.
public Intent setComponent (ComponentName component)
Added in API level 1

(Usually optional) Explicitly set the component to handle the intent. If left with the default value of null, the system will determine the appropriate class to use based on the other fields (action, data, type, categories) in the Intent. If this class is defined, the specified class will always be used regardless of the other fields. You should only set this value when you know you absolutely want a specific class to be used; otherwise it is better to let the system find the appropriate class so that you will respect the installed applications and user preferences.

Parameters
componentThe name of the application component to handle the intent, or null to let the system find one for you.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.
public Intent setData (Uri data)
Added in API level 1

Set the data this intent is operating on. This method automatically clears any type that was previously set by setType(String) or setTypeAndNormalize(String).

Note: scheme matching in the Android framework is case-sensitive, unlike the formal RFC. As a result, you should always write your Uri with a lower case scheme, or use normalizeScheme() or setDataAndNormalize(Uri) to ensure that the scheme is converted to lower case.

Parameters
dataThe Uri of the data this intent is now targeting.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.

         public Intent setDataAndType (Uri data, String type)
Added in API level 1

(Usually optional) Set the data for the intent along with an explicit MIME data type. This method should very rarely be used -- it allows you to override the MIME type that would ordinarily be inferred from the data with your own type given here.

Note: MIME type and Uri scheme matching in the Android framework is case-sensitive, unlike the formal RFC definitions. As a result, you should always write these elements with lower case letters, or use normalizeMimeType(String) or normalizeScheme() or setDataAndTypeAndNormalize(Uri, String) to ensure that they are converted to lower case.

Parameters
dataThe Uri of the data this intent is now targeting.
typeThe MIME type of the data being handled by this intent.
Returns
  • Returns the same Intent object, for chaining multiple calls into a single statement.


































  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值