An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in anIntentobject. This type of intent is called animplicitintent because it does not specify the app component to start, but instead specifies anactionand provides somedatawith which to perform the action.

When you callstartActivity()orstartActivityForResult()and pass it an implicit intent, the systemresolves the intentto an app that can handle the intent and starts its correspondingActivity. If there's more than one app that can handle the intent, the system presents the user with a dialog to pick which app to use.

This page describes several implicit intents that you can use to perform common actions, organized by the type of app that handles the intent. Each section also shows how you can create anintent filterto advertise your app's ability to perform the same action.

Caution:If there are no apps on the device that can receive the implicit intent, your app will crash when it callsstartActivity(). To first verify that an app exists to receive the intent, callresolveActivity()on yourIntentobject. If the result is non-null, there is at least one app that can handle the intent and it's safe to callstartActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that invokes the intent.

If you're not familiar with how to create intents or intent filters, you should first readIntents and Intent Filters.

To learn how to fire the intents listed on this page from your development host, seeVerify Intents with the Android Debug Bridge.

Google Now

Google Nowfires some of the intents listed on this page in response to voice commands. For more information, seeIntents Fired by Google Now.

Alarm Clock

Create an alarm


Note:
Only the hour, minutes, and message extras are available in Android 2.3 (API level 9) and higher. The other extras were added in later versions of the platform.To create a new alarm, use theACTION_SET_ALARMaction and specify alarm details such as the time and message using extras defined below.

Action
ACTION_SET_ALARM
Data URI
None
MIME Type
None
Extras
EXTRA_HOUR
The hour for the alarm.
EXTRA_MINUTES
The minutes for the alarm.
EXTRA_MESSAGE
A custom message to identify the alarm.
EXTRA_DAYS
An ArrayListincluding each week day on which this alarm should be repeated. Each day must be declared with an integer from the Calendarclass such as MONDAY.

For a one-time alarm, do not specify this extra.

EXTRA_RINGTONE
A content:URI specifying a ringtone to use with the alarm, or VALUE_RINGTONE_SILENTfor no ringtone.

To use the default ringtone, do not specify this extra.

EXTRA_VIBRATE
A boolean specifying whether to vibrate for this alarm.
EXTRA_SKIP_UI
A boolean specifying whether the responding app should skip its UI when setting the alarm. If true, the app should bypass any confirmation UI and simply set the specified alarm.

Example intent:

public void createAlarm(String message, int hour, int minutes) {  Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)      .putExtra(AlarmClock.EXTRA_MESSAGE, message)      .putExtra(AlarmClock.EXTRA_HOUR, hour)      .putExtra(AlarmClock.EXTRA_MINUTES, minutes);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}
Note:

In order to invoke theACTION_SET_ALARMintent, your app must have theSET_ALARMpermission:

<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.SET_ALARM" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Create a timer

To create a countdown timer, use theACTION_SET_TIMERaction and specify timer details such as the duration using extras defined below.

Note:This intent was added in Android 4.4 (API level 19).

Action
ACTION_SET_TIMER
Data URI
None
MIME Type
None
Extras
EXTRA_LENGTH
The length of the timer in seconds.
EXTRA_MESSAGE
A custom message to identify the timer.
EXTRA_SKIP_UI
A boolean specifying whether the responding app should skip its UI when setting the timer. If true, the app should bypass any confirmation UI and simply start the specified timer.

Example intent:

public void startTimer(String message, int seconds) {  Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER)      .putExtra(AlarmClock.EXTRA_MESSAGE, message)      .putExtra(AlarmClock.EXTRA_LENGTH, seconds)      .putExtra(AlarmClock.EXTRA_SKIP_UI, true);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}
Note:

In order to invoke theACTION_SET_TIMERintent, your app must have theSET_ALARMpermission:

<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.SET_TIMER" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Show all alarms

To show the list of alarms, use theACTION_SHOW_ALARMSaction.

Although not many apps will invoke this intent (it's primarily used by system apps), any app that behaves as an alarm clock should implement this intent filter and respond by showing the list of current alarms.

Note:This intent was added in Android 4.4 (API level 19).

Action
ACTION_SHOW_ALARMS
Data URI
None
MIME Type
None

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.SHOW_ALARMS" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Calendar

Add a calendar event

To add a new event to the user's calendar, use theACTION_INSERTaction and specify the data URI withEvents.CONTENT_URI. You can then specify various event details using extras defined below.

Action
ACTION_INSERT
Data URI
Events.CONTENT_URI
MIME Type
"vnd.android.cursor.dir/event"
Extras
EXTRA_EVENT_ALL_DAY
A boolean specifying whether this is an all-day event.
EXTRA_EVENT_BEGIN_TIME
The start time of the event (milliseconds since epoch).
EXTRA_EVENT_END_TIME
The end time of the event (milliseconds since epoch).
TITLE
The event title.
DESCRIPTION
The event description.
EVENT_LOCATION
The event location.
EXTRA_EMAIL
A comma-separated list of email addresses that specify the invitees.

Many more event details can be specified using the constants defined in theCalendarContract.EventsColumnsclass.

Example intent:

public void addEvent(String title, String location, Calendar begin, Calendar end) {  Intent intent = new Intent(Intent.ACTION_INSERT)      .setData(Events.CONTENT_URI)      .putExtra(Events.TITLE, title)      .putExtra(Events.EVENT_LOCATION, location)      .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin)      .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.INSERT" />    <data android:mimeType="vnd.android.cursor.dir/event" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Camera

Capture a picture or video and return it

To open a camera app and receive the resulting photo or video, use theACTION_IMAGE_CAPTUREorACTION_VIDEO_CAPTUREaction. Also specify the URI location where you'd like the camera to save the photo or video, in theEXTRA_OUTPUTextra.

Action
ACTION_IMAGE_CAPTUREor
ACTION_VIDEO_CAPTURE
Data URI Scheme
None
MIME Type
None
Extras
EXTRA_OUTPUT
The URI location where the camera app should save the photo or video file (as a Uriobject).

When the camera app successfully returns focus to your activity (your app receives theonActivityResult()callback), you can access the photo or video at the URI you specified with theEXTRA_OUTPUTvalue.

Note:When you useACTION_IMAGE_CAPTUREto capture a photo, the camera may also return a downscaled copy (a thumbnail) of the photo in the resultIntent, saved as aBitmapin an extra field named"data".

Example intent:

static final int REQUEST_IMAGE_CAPTURE = 1;static final Uri mLocationForPhotos;public void capturePhoto(String targetFilename) {  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  intent.putExtra(MediaStore.EXTRA_OUTPUT,      Uri.withAppendedPath(mLocationForPhotos, targetFilename));  if (intent.resolveActivity(getPackageManager()) != null) {    startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);  }}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {  if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {    Bitmap thumbnail = data.getParcelable("data");    // Do other work with full size photo saved in mLocationForPhotos    ...  }}

For more information about how to use this intent to capture a photo, including how to create an appropriateUrifor the output location, readTaking Photos SimplyorTaking Videos Simply.

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.media.action.IMAGE_CAPTURE" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

When handling this intent, your activity should check for theEXTRA_OUTPUTextra in the incomingIntent, then save the captured image or video at the location specified by that extra and callsetResult()with anIntentthat includes a compressed thumbnail in an extra named"data".

Start a camera app in still image mode


Action
To open a camera app in still image mode, use theINTENT_ACTION_STILL_IMAGE_CAMERAaction.

INTENT_ACTION_STILL_IMAGE_CAMERA
Data URI Scheme
None
MIME Type
None
Extras
None

Example intent:

public void capturePhoto() {  Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivityForResult(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.media.action.STILL_IMAGE_CAMERA" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Start a camera app in video mode

ActionTo open a camera app in video mode, use theINTENT_ACTION_VIDEO_CAMERAaction.

INTENT_ACTION_VIDEO_CAMERA
Data URI Scheme
None
MIME Type
None
Extras
None

Example intent:

public void capturePhoto() {  Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivityForResult(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.media.action.VIDEO_CAMERA" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Contacts/People App

Select a contact

To have the user select a contact and provide your app access to all the contact information, use theACTION_PICKaction and specify the MIME type toContacts.CONTENT_TYPE.

The resultIntentdelivered to youronActivityResult()callback contains thecontent:URI pointing to the selected contact. The response grants your app temporary permissions to read that contact using theContacts ProviderAPI even if your app does not include theREAD_CONTACTSpermission.

Tip:If you need access to only a specific piece of contact information, such as a phone number or email address, instead see the next section about how toselect specific contact data.

Action
ACTION_PICK
Data URI Scheme
None
MIME Type
Contacts.CONTENT_TYPE

Example intent:

static final int REQUEST_SELECT_CONTACT = 1;public void selectContact() {  Intent intent = new Intent(Intent.ACTION_PICK);  intent.setType(ContactsContract.Contacts.CONTENT_TYPE);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivityForResult(intent, REQUEST_SELECT_CONTACT);  }}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {  if (requestCode == REQUEST_SELECT_CONTACT && resultCode == RESULT_OK) {    Uri contactUri = data.getData();    // Do something with the selected contact at contactUri    ...  }}

For information about how to retrieve contact details once you have the contact URI, readRetrieving Details for a Contact. Remember, when you retrieve the contact URI with the above intent, youdo notneed theREAD_CONTACTSpermission to read details for that contact.

Select specific contact data

To have the user select a specific piece of information from a contact, such as a phone number, email address, or other data type, use theACTION_PICKaction and specify the MIME type to one of the content types listed below, such asCommonDataKinds.Phone.CONTENT_TYPEto get the contact's phone number.

If you need to retrieve only one type of data from a contact, this technique with aCONTENT_TYPEfrom theContactsContract.CommonDataKindsclasses is more efficient than using theContacts.CONTENT_TYPE(as shown in the previous section) because the result provides you direct access to the desired data without requiring you to perform a more complex query toContacts Provider.

The resultIntentdelivered to youronActivityResult()callback contains thecontent:URI pointing to the selected contact data. The response grants your app temporary permissions to read that contact data even if your app does not include theREAD_CONTACTSpermission.

Action
ACTION_PICK
Data URI Scheme
None
MIME Type
CommonDataKinds.Phone.CONTENT_TYPE
Pick from contacts with a phone number.
CommonDataKinds.Email.CONTENT_TYPE
Pick from contacts with an email address.
CommonDataKinds.StructuredPostal.CONTENT_TYPE
Pick from contacts with a postal address.

Or one of many otherCONTENT_TYPEvalues underContactsContract.

Example intent:

static final int REQUEST_SELECT_PHONE_NUMBER = 1;public void selectContact() {  // Start an activity for the user to pick a phone number from contacts  Intent intent = new Intent(Intent.ACTION_PICK);  intent.setType(CommonDataKinds.Phone.CONTENT_TYPE);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivityForResult(intent, REQUEST_SELECT_PHONE_NUMBER);  }}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {  if (requestCode == REQUEST_SELECT_PHONE_NUMBER && resultCode == RESULT_OK) {    // Get the URI and query the content provider for the phone number    Uri contactUri = data.getData();    String[] projection = new String[]{CommonDataKinds.Phone.NUMBER};    Cursor cursor = getContentResolver().query(contactUri, projection,        null, null, null);    // If the cursor returned is valid, get the phone number    if (cursor != null && cursor.moveToFirst()) {      int numberIndex = cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER);      String number = cursor.getString(numberIndex);      // Do something with the phone number      ...    }  }}

View a contact

To display the details for a known contact, use theACTION_VIEWaction and specify the contact with acontent:URI as the intent data.

There are primarily two ways to initially retrieve the contact's URI:

  • Use the contact URI returned by theACTION_PICK, shown in the previous section (this approach does not require any app permissions).
  • Access the list of all contacts directly, as described inRetrieving a List of Contacts(this approach requires theREAD_CONTACTSpermission).
Action
ACTION_VIEW
Data URI Scheme
content:<URI>
MIME Type
None. The type is inferred from contact URI.

Example intent:

public void viewContact(Uri contactUri) {  Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Edit an existing contact

To edit a known contact, use theACTION_EDITaction, specify the contact with acontent:URI as the intent data, and include any known contact information in extras specified by constants inContactsContract.Intents.Insert.

There are primarily two ways to initially retrieve the contact URI:

  • Use the contact URI returned by theACTION_PICK, shown in the previous section (this approach does not require any app permissions).
  • Access the list of all contacts directly, as described inRetrieving a List of Contacts(this approach requires theREAD_CONTACTSpermission).
Action
ACTION_EDIT
Data URI Scheme
content:<URI>
MIME Type
The type is inferred from contact URI.
Extras
One or more of the extras defined in ContactsContract.Intents.Insertso you can populate fields of the contact details.

Example intent:

public void editContact(Uri contactUri, String email) {  Intent intent = new Intent(Intent.ACTION_EDIT);  intent.setData(contactUri);  intent.putExtra(Intents.Insert.EMAIL, email);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

For more information about how to edit a contact, readModifying Contacts Using Intents.

Insert a contact

To insert a new contact, use theACTION_INSERTaction, specifyContacts.CONTENT_TYPEas the MIME type, and include any known contact information in extras specified by constants inContactsContract.Intents.Insert.

Action
ACTION_INSERT
Data URI Scheme
None
MIME Type
Contacts.CONTENT_TYPE
Extras
One or more of the extras defined in ContactsContract.Intents.Insert.

Example intent:

public void insertContact(String name, String email) {  Intent intent = new Intent(Intent.ACTION_INSERT);  intent.setType(Contacts.CONTENT_TYPE);  intent.putExtra(Intents.Insert.NAME, name);  intent.putExtra(Intents.Insert.EMAIL, email);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

For more information about how to insert a contact, readModifying Contacts Using Intents.

Email

Compose an email with optional attachments

To compose an email, use one of the below actions based on whether you'll include attachments, and include email details such as the recipient and subject using the extra keys listed below.

Action
ACTION_SENDTO(for no attachment) or
ACTION_SEND(for one attachment) or
ACTION_SEND_MULTIPLE(for multiple attachments)
Data URI Scheme
None
MIME Type
"text/plain"
"*/*"
Extras
Intent.EXTRA_EMAIL
A string array of all "To" recipient email addresses.
Intent.EXTRA_CC
A string array of all "CC" recipient email addresses.
Intent.EXTRA_BCC
A string array of all "BCC" recipient email addresses.
Intent.EXTRA_SUBJECT
A string with the email subject.
Intent.EXTRA_TEXT
A string with the body of the email.
Intent.EXTRA_STREAM
A Uripointing to the attachment. If using the ACTION_SEND_MULTIPLEaction, this should instead be an ArrayListcontaining multiple Uriobjects.

Example intent:

public void composeEmail(String[] addresses, String subject, Uri attachment) {  Intent intent = new Intent(Intent.ACTION_SEND);  intent.setType("*/*");  intent.putExtra(Intent.EXTRA_EMAIL, addresses);  intent.putExtra(Intent.EXTRA_SUBJECT, subject);  intent.putExtra(Intent.EXTRA_STREAM, attachment);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

If you want to ensure that your intent is handled only by an email app (and not other text messaging or social apps), then use theACTION_SENDTOaction and include the"mailto:"data scheme. For example:

public void composeEmail(String[] addresses, String subject) {  Intent intent = new Intent(Intent.ACTION_SENDTO);  intent.setData(Uri.parse("mailto:")); // only email apps should handle this  intent.putExtra(Intent.EXTRA_EMAIL, addresses);  intent.putExtra(Intent.EXTRA_SUBJECT, subject);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.SEND" />    <data android:type="*/*" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter>  <intent-filter>    <action android:name="android.intent.action.SENDTO" />    <data android:scheme="mailto" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

File Storage

Retrieve a specific type of file

To request that the user select a file such as a document or photo and return a reference to your app, use theACTION_GET_CONTENTaction and specify your desired MIME type. The file reference returned to your app is transient to your activity's current lifecycle, so if you want to access it later you must import a copy that you can read later. This intent also allows the user to create a new file in the process (for example, instead of selecting an existing photo, the user can capture a new photo with the camera).

The result intent delivered to youronActivityResult()method includes data with a URI pointing to the file. The URI could be anything, such as anhttp:URI,file:URI, orcontent:URI. However, if you'd like to restrict selectable files to only those that are accessible from a content provider (acontent:URI) and that are available as a file stream withopenFileDescriptor(), you should add theCATEGORY_OPENABLEcategory to your intent.

On Android 4.3 (API level 18) and higher, you can also allow the user to select multiple files by addingEXTRA_ALLOW_MULTIPLEto the intent, set totrue. You can then access each of the selected files in aClipDataobject returned bygetClipData().

Action
ACTION_GET_CONTENT
Data URI Scheme
None
MIME Type
The MIME type corresponding to the file type the user should select.
Extras
EXTRA_ALLOW_MULTIPLE
A boolean declaring whether the user can select more than one file at a time.
EXTRA_LOCAL_ONLY
A boolean that declares whether the returned file must be available directly from the device, rather than requiring a download from a remote service.
Category(optional)
CATEGORY_OPENABLE
To return only "openable" files that can be represented as a file stream with openFileDescriptor().

Example intent to get a photo:

static final int REQUEST_IMAGE_GET = 1;public void selectImage() {  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  intent.setType("image/*");  if (intent.resolveActivity(getPackageManager()) != null) {    startActivityForResult(intent, REQUEST_IMAGE_GET);  }}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {  if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) {    Bitmap thumbnail = data.getParcelable("data");    Uri fullPhotoUri = data.getData();    // Do work with photo saved at fullPhotoUri    ...  }}

Example intent filter to return a photo:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.GET_CONTENT" />    <data android:type="image/*" />    <category android:name="android.intent.category.DEFAULT" />    <!-- The OPENABLE category declares that the returned file is accessible      from a content provider that supports OpenableColumns      and ContentResolver.openFileDescriptor() -->    <category android:name="android.intent.category.OPENABLE" />  </intent-filter></activity>

Open a specific type of file

Instead of retrieving a copy of a file that you must import to your app (by using theACTION_GET_CONTENTaction), when running on Android 4.4 or higher, you can instead request toopena file that's managed by another app by using theACTION_OPEN_DOCUMENTaction and specifying a MIME type. To also allow the user to instead create a new document that your app can write to, use theACTION_CREATE_DOCUMENTaction instead. For example, instead of selecting from existing PDF documents, theACTION_CREATE_DOCUMENTintent allows users to select where they'd like to create a new document (within another app that manages the document's storage)—your app then receives the URI location of where it can write the new document.

Whereas the intent delivered to youronActivityResult()method from theACTION_GET_CONTENTaction may return a URI of any type, the result intent fromACTION_OPEN_DOCUMENTandACTION_CREATE_DOCUMENTalways specify the chosen file as acontent:URI that's backed by aDocumentsProvider. You can open the file withopenFileDescriptor()and query its details using columns fromDocumentsContract.Document.

The returned URI grants your app long-term read access to the file (also possibly with write access). So theACTION_OPEN_DOCUMENTaction is particularly useful (instead of usingACTION_GET_CONTENT) when you want to read an existing file without making a copy into your app, or when you want to open and edit a file in place.

You can also allow the user to select multiple files by addingEXTRA_ALLOW_MULTIPLEto the intent, set totrue. If the user selects just one item, then you can retrieve the item fromgetData(). If the user selects more than one item, thengetData()returns null and you must instead retrieve each item from aClipDataobject that is returned bygetClipData().

Note:Your intentmustspecify a MIME type andmustdeclare theCATEGORY_OPENABLEcategory. If appropriate, you can specify more than one MIME type by adding an array of MIME types with theEXTRA_MIME_TYPESextra—if you do so, you must set the primary MIME type insetType()to"*/*".

Action
ACTION_OPEN_DOCUMENTor
ACTION_CREATE_DOCUMENT
Data URI Scheme
None
MIME Type
The MIME type corresponding to the file type the user should select.
Extras
EXTRA_MIME_TYPES
An array of MIME types corresponding to the types of files your app is requesting. When you use this extra, you must set the primary MIME type in setType()to "*/*".
EXTRA_ALLOW_MULTIPLE
A boolean that declares whether the user can select more than one file at a time.
EXTRA_TITLE
For use with ACTION_CREATE_DOCUMENTto specify an initial file name.
EXTRA_LOCAL_ONLY
A boolean that declares whether the returned file must be available directly from the device, rather than requiring a download from a remote service.
Category
CATEGORY_OPENABLE
To return only "openable" files that can be represented as a file stream with openFileDescriptor().

Example intent to get a photo:

static final int REQUEST_IMAGE_OPEN = 1;public void selectImage() {  Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);  intent.setType("image/*");  intent.addCategory(Intent.CATEGORY_OPENABLE);  // Only the system receives the ACTION_OPEN_DOCUMENT, so no need to test.  startActivityForResult(intent, REQUEST_IMAGE_OPEN);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {  if (requestCode == REQUEST_IMAGE_OPEN && resultCode == RESULT_OK) {    Uri fullPhotoUri = data.getData();    // Do work with full size photo saved at fullPhotoUri    ...  }}

Third party apps cannot actually respond to an intent with theACTION_OPEN_DOCUMENTaction. Instead, the system receives this intent and displays all the files available from various apps in a unified user interface.

To provide your app's files in this UI and allow other apps to open them, you must implement aDocumentsProviderand include an intent filter forPROVIDER_INTERFACE("android.content.action.DOCUMENTS_PROVIDER"). For example:

<provider ...  android:grantUriPermissions="true"  android:exported="true"  android:permission="android.permission.MANAGE_DOCUMENTS">  <intent-filter>    <action android:name="android.content.action.DOCUMENTS_PROVIDER" />  </intent-filter></provider>

For more information about how to make the files managed by your app openable from other apps, read theStorage Access Frameworkguide.

Local Actions

Call a car

Note:Apps must ask for confirmation from the user before completing the action.To call a taxi, use theACTION_RESERVE_TAXI_RESERVATIONaction.

Action
ACTION_RESERVE_TAXI_RESERVATION
Data URI
None
MIME Type
None
Extras
None

Example intent:

public void callCar() {  Intent intent = new Intent(ReserveIntents.ACTION_RESERVE_TAXI_RESERVATION);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="com.google.android.gms.actions.RESERVE_TAXI_RESERVATION" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Maps

Show a location on a map

To open a map, use theACTION_VIEWaction and specify the location information in the intent data with one of the schemes defined below.

Action
ACTION_VIEW
Data URI Scheme
geo:latitude,longitude
Show the map at the given longitude and latitude.

Example:"geo:47.6,-122.3"

geo:latitude,longitude?z=zoom
Show the map at the given longitude and latitude at a certain zoom level. A zoom level of 1 shows the whole Earth, centered at the given lat, lng. The highest (closest) zoom level is 23.

Example:"geo:47.6,-122.3?z=11"

geo:0,0?q=lat,lng(label)
Show the map at the given longitude and latitude with a string label.

Example:"geo:0,0?q=34.99,-106.61(Treasure)"

geo:0,0?q=my+street+address
Show the location for "my street address" (may be a specific address or location query).

Example:"geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA"

Note:All strings passed in thegeoURI must be encoded. For example, the string1st & Pike, Seattleshould become1st%20%26%20Pike%2C%20Seattle. Spaces in the string can be encoded with%20or replaced with the plus sign (+).

MIME Type
None

Example intent:

public void showMap(Uri geoLocation) {  Intent intent = new Intent(Intent.ACTION_VIEW);  intent.setData(geoLocation);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.VIEW" />    <data android:scheme="geo" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Music or Video

Play a media file

To play a music file, use theACTION_VIEWaction and specify the URI location of the file in the intent data.

Action
ACTION_VIEW
Data URI Scheme
file:<URI>
content:<URI>
http:<URL>
MIME Type
"audio/*"
"application/ogg"
"application/x-ogg"
"application/itunes"
Or any other that your app may require.

Example intent:

public void playMedia(Uri file) {  Intent intent = new Intent(Intent.ACTION_VIEW);  intent.setData(file);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.VIEW" />    <data android:type="audio/*" />    <data android:type="application/ogg" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Play music based on a search query


This intent should include theEXTRA_MEDIA_FOCUSstring extra, which specifies the inteded search mode. For example, the search mode can specify whether the search is for an artist name or song name.To play music based on a search query, use theINTENT_ACTION_MEDIA_PLAY_FROM_SEARCHintent. An app may fire this intent in response to the user's voice command to play music. The receiving app for this intent performs a search within its inventory to match existing content to the given query and starts playing that content.

Action
INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH
Data URI Scheme
None
MIME Type
None
Extras
MediaStore.EXTRA_MEDIA_FOCUS(required)

Indicates the search mode (whether the user is looking for a particular artist, album, song, or playlist). Most search modes take additional extras. For example, if the user is interested in listening to a particular song, the intent might have three additional extras: the song title, the artist, and the album. This intent supports the following search modes for each value ofEXTRA_MEDIA_FOCUS:

Any-"vnd.android.cursor.item/*"

Play any music. The receiving app should play some music based on a smart choice, such as the last playlist the user listened to.

Additional extras:

  • QUERY(required) - An empty string. This extra is always provided for backward compatibility: existing apps that do not know about search modes can process this intent as an unstructured search.

Unstructured-"vnd.android.cursor.item/*"

Play a particular song, album or genre from an unstructured search query. Apps may generate an intent with this search mode when they can't identify the type of content the user wants to listen to. Apps should use more specific search modes when possible.

Additional extras:

  • QUERY(required) - A string that contains any combination of: the artist, the album, the song name, or the genre.

Genre-Audio.Genres.ENTRY_CONTENT_TYPE

Play music of a particular genre.

Additional extras:

  • "android.intent.extra.genre"(required) - The genre.
  • QUERY(required) - The genre. This extra is always provided for backward compatibility: existing apps that do not know about search modes can process this intent as an unstructured search.

Artist-Audio.Artists.ENTRY_CONTENT_TYPE

Play music from a particular artist.

Additional extras:

  • EXTRA_MEDIA_ARTIST(required) - The artist.
  • "android.intent.extra.genre"- The genre.
  • QUERY(required) - A string that contains any combination of the artist or the genre. This extra is always provided for backward compatibility: existing apps that do not know about search modes can process this intent as an unstructured search.

Album-Audio.Albums.ENTRY_CONTENT_TYPE

Play music from a particular album.

Additional extras:

  • EXTRA_MEDIA_ALBUM(required) - The album.
  • EXTRA_MEDIA_ARTIST- The artist.
  • "android.intent.extra.genre"- The genre.
  • QUERY(required) - A string that contains any combination of the album or the artist. This extra is always provided for backward compatibility: existing apps that do not know about search modes can process this intent as an unstructured search.

Song-"vnd.android.cursor.item/audio"

Play a particular song.

Additional extras:

  • EXTRA_MEDIA_ALBUM- The album.
  • EXTRA_MEDIA_ARTIST- The artist.
  • "android.intent.extra.genre"- The genre.
  • EXTRA_MEDIA_TITLE(required) - The song name.
  • QUERY(required) - A string that contains any combination of: the album, the artist, the genre, or the title. This extra is always provided for backward compatibility: existing apps that do not know about search modes can process this intent as an unstructured search.

Playlist-Audio.Playlists.ENTRY_CONTENT_TYPE

Play a particular playlist or a playlist that matches some criteria specified by additional extras.

Additional extras:

  • EXTRA_MEDIA_ALBUM- The album.
  • EXTRA_MEDIA_ARTIST- The artist.
  • "android.intent.extra.genre"- The genre.
  • "android.intent.extra.playlist"- The playlist.
  • EXTRA_MEDIA_TITLE- The song name that the playlist is based on.
  • QUERY(required) - A string that contains any combination of: the album, the artist, the genre, the playlist, or the title. This extra is always provided for backward compatibility: existing apps that do not know about search modes can process this intent as an unstructured search.

Example intent:

If the user wants to listen to music from a particular artist, a search app may generate the following intent:

public void playSearchArtist(String artist) {  Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);  intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,          MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);  intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);  intent.putExtra(SearchManager.QUERY, artist);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

When handling this intent, your activity should check the value of theEXTRA_MEDIA_FOCUSextra in the incomingIntentto determine the search mode. Once your activity has identified the search mode, it should read the values of the additional extras for that particular search mode. With this information your app can then perform the search within its inventory to play the content that matches the search query. For example:

protected void onCreate(Bundle savedInstanceState) {  ...  Intent intent = this.getIntent();  if (intent.getAction().compareTo(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH) == 0) {    String mediaFocus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS);    String query = intent.getStringExtra(SearchManager.QUERY);    // Some of these extras may not be available depending on the search mode    String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);    String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);    String genre = intent.getStringExtra("android.intent.extra.genre");    String playlist = intent.getStringExtra("android.intent.extra.playlist");    String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);    // Determine the search mode and use the corresponding extras    if (mediaFocus == null) {      // 'Unstructured' search mode (backward compatible)      playUnstructuredSearch(query);    } else if (mediaFocus.compareTo("vnd.android.cursor.item/*") == 0) {      if (query.isEmpty()) {        // 'Any' search mode        playResumeLastPlaylist();      } else {        // 'Unstructured' search mode        playUnstructuredSearch(query);      }    } else if (mediaFocus.compareTo(MediaStore.Audio.Genres.ENTRY_CONTENT_TYPE) == 0) {      // 'Genre' search mode      playGenre(genre);    } else if (mediaFocus.compareTo(MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE) == 0) {      // 'Artist' search mode      playArtist(artist, genre);    } else if (mediaFocus.compareTo(MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE) == 0) {      // 'Album' search mode      playAlbum(album, artist);    } else if (mediaFocus.compareTo("vnd.android.cursor.item/audio") == 0) {      // 'Song' search mode      playSong(album, artist, genre, title);    } else if (mediaFocus.compareTo(MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE) == 0) {      // 'Playlist' search mode      playPlaylist(album, artist, genre, playlist, title);    }  }}

New Note

Create a note

To create a new note, use theACTION_CREATE_NOTEaction and specify note details such as the subject and text using extras defined below.

Note:Apps must ask for confirmation from the user before completing the action.

Category Details and Examples Action Name
Alarm

Set alarm

  • "set an alarm for 7 am"
AlarmClock.ACTION_SET_ALARM

Set timer

  • "set a timer for 5 minutes"
AlarmClock.ACTION_SET_TIMER
Communication

Call a number

  • "call 555-5555"
  • "call bob"
  • "call voicemail"
Intent.ACTION_CALL
Local

Book a car

  • "call me a car"
  • "book me a taxi"
ReserveIntents
.ACTION_RESERVE_TAXI_RESERVATION
Media

Play music from search

  • "play michael jackson billie jean"
MediaStore
.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH

Take a picture

  • "take a picture"
MediaStore
.INTENT_ACTION_STILL_IMAGE_CAMERA

Record a video

  • "record a video"
MediaStore
.INTENT_ACTION_VIDEO_CAMERA
Search

Search using a specific app

  • "search for cat videos
    on myvideoapp"
"com.google.android.gms.actions
.SEARCH_ACTION"
Web browser

Open URL

  • "open example.com"
Intent.ACTION_VIEW

Action
ACTION_CREATE_NOTE
Data URI Scheme
None
MIME Type
PLAIN_TEXT_TYPE
"*/*"
Extras
EXTRA_NAME
A string indicating the title or subject of the note.
EXTRA_TEXT
A string indicating the text of the note.

Example intent:

public void createNote(String subject, String text) {  Intent intent = new Intent(NoteIntents.ACTION_CREATE_NOTE)      .putExtra(NoteIntents.EXTRA_NAME, subject)      .putExtra(NoteIntents.EXTRA_TEXT, text);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="com.google.android.gms.actions.CREATE_NOTE" />    <category android:name="android.intent.category.DEFAULT" />    <data android:mimeType=”*/*”>  </intent-filter></activity>

Phone

Initiate a phone call

To open the phone app and dial a phone number, use theACTION_DIALaction and specify a phone number using the URI scheme defined below. When the phone app opens, it displays the phone number but the user must press theCallbutton to begin the phone call.


TheACTION_CALLaction requires that you add theCALL_PHONEpermission to your manifest file:To place a phone call directly, use theACTION_CALLaction and specify a phone number using the URI scheme defined below. When the phone app opens, it begins the phone call; the user does not need to press theCallbutton.

<uses-permission android:name="android.permission.CALL_PHONE" />
Action
  • ACTION_DIAL- Opens the dialer or phone app.
  • ACTION_CALL- Places a phone call (requires theCALL_PHONEpermission)
Data URI Scheme
  • tel:<phone-number>
  • voicemail:<phone-number>
MIME Type
None

Valid telephone numbers are those defined inthe IETF RFC 3966. Valid examples include the following:

  • tel:2125551212
  • tel:(212) 555 1212

The Phone's dialer is good at normalizing schemes, such as telephone numbers. So the scheme described isn't strictly required in theUri.parse()method. However, if you have not tried a scheme or are unsure whether it can be handled, use theUri.fromParts()method instead.

Example intent:

public void dialPhoneNumber(String phoneNumber) {  Intent intent = new Intent(Intent.ACTION_DIAL);  intent.setData(Uri.parse("tel:" + phoneNumber));  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Search using a specific app



Voice search in your app

To support search within the context of your app, declare an intent filter in your app with theSEARCH_ACTIONaction, as shown in the example intent filter below.

Action
"com.google.android.gms.actions.SEARCH_ACTION"
Support search queries from Google Now.
Extras
QUERY
A string that contains the search query.

Example intent filter:

<activity android:name=".SearchActivity">  <intent-filter>    <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>    <category android:name="android.intent.category.DEFAULT"/>  </intent-filter></activity>

Perform a web search

To initiate a web search, use theACTION_WEB_SEARCHaction and specify the search string in theSearchManager.QUERYextra.

Action
ACTION_WEB_SEARCH
Data URI Scheme
None
MIME Type
None
Extras
SearchManager.QUERY
The search string.

Example intent:

public void searchWeb(String query) {  Intent intent = new Intent(Intent.ACTION_SEARCH);  intent.putExtra(SearchManager.QUERY, query);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Settings

Open a specific section of Settings

To open a screen in the system settings when your app requires the user to change something, use one of the following intent actions to open the settings screen respective to the action name.

Action
ACTION_SETTINGS
ACTION_WIRELESS_SETTINGS
ACTION_AIRPLANE_MODE_SETTINGS
ACTION_WIFI_SETTINGS
ACTION_APN_SETTINGS
ACTION_BLUETOOTH_SETTINGS
ACTION_DATE_SETTINGS
ACTION_LOCALE_SETTINGS
ACTION_INPUT_METHOD_SETTINGS
ACTION_DISPLAY_SETTINGS
ACTION_SECURITY_SETTINGS
ACTION_LOCATION_SOURCE_SETTINGS
ACTION_INTERNAL_STORAGE_SETTINGS
ACTION_MEMORY_CARD_SETTINGS

See theSettingsdocumentation for additional settings screens that are available.

Data URI Scheme
None
MIME Type
None

Example intent:

public void openWifiSettings() {  Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Text Messaging

Compose an SMS/MMS message with attachment

To initiate an SMS or MMS text message, use one of the intent actions below and specify message details such as the phone number, subject, and message body using the extra keys listed below.

Action
ACTION_SENDTOor
ACTION_SENDor
ACTION_SEND_MULTIPLE
Data URI Scheme
sms:<phone_number>
smsto:<phone_number>
mms:<phone_number>
mmsto:<phone_number>

Each of these schemes are handled the same.

MIME Type
"text/plain"
"image/*"
"video/*"
Extras
"subject"
A string for the message subject (usually for MMS only).
"sms_body"
A string for the text message.
EXTRA_STREAM
A Uripointing to the image or video to attach. If using the ACTION_SEND_MULTIPLEaction, this extra should be an ArrayListof Uris pointing to the images/videos to attach.

Example intent:

public void composeMmsMessage(String message, Uri attachment) {  Intent intent = new Intent(Intent.ACTION_SENDTO);  intent.setType(HTTP.PLAIN_TEXT_TYPE);  intent.putExtra("sms_body", message);  intent.putExtra(Intent.EXTRA_STREAM, attachment);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

If you want to ensure that your intent is handled only by a text messaging app (and not other email or social apps), then use theACTION_SENDTOaction and include the"smsto:"data scheme. For example:

public void composeMmsMessage(String message, Uri attachment) {  Intent intent = new Intent(Intent.ACTION_SEND);  intent.setData(Uri.parse("smsto:")); // This ensures only SMS apps respond  intent.putExtra("sms_body", message);  intent.putExtra(Intent.EXTRA_STREAM, attachment);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.SEND" />    <data android:type="text/plain" />    <data android:type="image/*" />    <category android:name="android.intent.category.DEFAULT" />  </intent-filter></activity>

Note:If you're developing an SMS/MMS messaging app, you must implement intent filters for several additional actions in order to be available as thedefault SMS appon Android 4.4 and higher. For more information, see the documentation atTelephony.

Web Browser

Load a web URL


Action
To open a web page, use theACTION_VIEWaction and specify the web URL in the intent data.

ACTION_VIEW
Data URI Scheme
http:<URL>
https:<URL>
MIME Type
"text/plain"
"text/html"
"application/xhtml+xml"
"application/vnd.wap.xhtml+xml"

Example intent:

public void openWebPage(String url) {  Uri webpage = Uri.parse(url);  Intent intent = new Intent(Intent.ACTION_VIEW, webpage);  if (intent.resolveActivity(getPackageManager()) != null) {    startActivity(intent);  }}

Example intent filter:

<activity ...>  <intent-filter>    <action android:name="android.intent.action.VIEW" />    <!-- Include the host attribute if you want your app to respond      only to URLs with your app's domain. -->    <data android:scheme="http" android:host="www.example.com" />    <category android:name="android.intent.category.DEFAULT" />    <!-- The BROWSABLE category is required to get links from web pages. -->    <category android:name="android.intent.category.BROWSABLE" />  </intent-filter></activity>

Tip:If your Android app provides functionality similar to your web site, include an intent filter for URLs that point to your web site. Then, if users have your app installed, links from emails or other web pages pointing to your web site open your Android app instead of your web page.

Verify Intents with the Android Debug Bridge

To verify that your app responds to the intents that you want to support, you can use theadbtool to fire specific intents:

  1. Set up an Android device fordevelopment, or use avirtual device.
  2. Install a version of your app that handles the intents you want to support.
  3. Fire an intent usingadb:
    adb shell am start -a <ACTION> -t <MIME_TYPE> -d <DATA> \  -e <EXTRA_NAME> <EXTRA_VALUE> -n <ACTIVITY>

    For example:

    adb shell am start -a android.intent.action.DIAL \  -d tel:555-5555 -n org.example.MyApp/.MyActivity
  4. If you defined the required intent filters, your app should handle the intent.

For more information, seeADB Shell Commands.

Intents Fired by Google Now

Google Nowrecognizes many voice commands and fires intents for them. As such, users may launch your app with a Google Now voice command if your app declares the corresponding intent filter. For example, if your app canset an alarmand you add the corresponding intent filter to your manifest file, Google Now lets users choose your app when they request to set an alarm, as shown in figure 1.

Figure 1.Google Now lets users choose from installed apps that support a given action.

Google Now recognizes voice commands for the actions listed in table 1. For more information about declaring each intent filter, click on the action description.

Table 1.Voice commands recognized by Google Now (Google Search app v3.6)

一个意图可以让你通过描述一个简单的动作,你想执行(如“查看地图”或“拍照”)在启动其他应用程式的活动意图对象。这种类型的意图被称为隐含的意图,因为它没有指定的应用程序组件开始,而是指定了一个动作,并提供了一些数据,用以执行的操作。

当你调用startActivity()startActivityForResult()并将它传递一个隐含的意图,该系统解决了意向到一个应用程序,可以处理这个意图并开始相应的活动。如果有一个以上的应用程序,可以处理这个意图,系统显示一个对话框,用户挑选使用哪个应用程序。

此页面介绍了可用于执行共同行动,通过处理该意图的应用类型组织了多次隐含意图。每个部分还展示了如何创建一个意图过滤器来宣传您的应用程序的执行相同的操作能力。

注意:如果有可以接收隐含意图在设备上安装任何应用,当它调用您的应用程序会崩溃startActivity()。首先验证一个应用程序是否存在接收的意图,调用resolveActivity()您的意向对象。如果结果是非空,至少有一个应用程序能够处理的意图和它的安全调用startActivity()。如果结果为空,你不应该使用的意图,可能的话,你应该禁用调用的意图的功能。

如果你不熟悉如何创建意图或意图过滤器,您应该先阅读意图和意图过滤器。

要了解如何激发您的开发主机此页面上列出的意图,看到验证了Android调试桥意图。

现在谷歌

谷歌现在触发一些响应语音命令在此页面上列出的意图的。欲了解更多信息,请参阅由谷歌解雇现在意图。

闹钟

创建一个报警


注:
只有小时,分钟和额外的消息在的Android 2.3(API等级9)和更高可用。在该平台的后续版本中添加了其他额外。要创建一个新的警报,使用ACTION_SET_ALARM行动,并指定报警的详细信息,如下面定义的时间和使用消息临时演员。

行动
ACTION_SET_ALARM
数据URI
没有
MIME类型
没有
附加功能
EXTRA_HOUR
报警的时间。
EXTRA_MINUTES
该分钟报警。
EXTRA_MESSAGE
自定义消息,识别报警。
EXTRA_DAYS
一个 ArrayList中包括每个工作日上应重复此警报。每天必须从一个整数声明 日历类,如 周一

对于一次性报警,不指定该额外费用。

EXTRA_RINGTONE
一个 内容:URI指定一个铃声与报警,或者使用 VALUE_RINGTONE_SILENT无铃声。

要使用默认的铃声,不指定该额外费用。

EXTRA_VIBRATE
一个布尔值指定是否为此报警振动。
EXTRA_SKIP_UI
一个布尔值,指定设置报警时响应的应用程​​序是否应该跳过它的UI。如果为true,应用程序应该绕过任何确认的用户界面和简单的设置指定的报警。

举例意图:

public  void createAlarm ( String message ,  int hour ,  int minutes )  {   Intent intent =  new  Intent ( AlarmClock . ACTION_SET_ALARM )       . putExtra ( AlarmClock . EXTRA_MESSAGE , message )       . putExtra ( AlarmClock . EXTRA_HOUR , hour )       . putExtra ( AlarmClock . EXTRA_MINUTES , minutes );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }
注意:

为了调用ACTION_SET_ALARM意图,您的应用程序必须有SET_ALARM权限:

<使用许可权 的android:名称= “com.android.alarm.permission.SET_ALARM”  />

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.SET_ALARM"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

创建一个定时器


注:
此意图是在Android 4.4系统(API级别19)补充道。要创建一个倒数计时器,使用ACTION_SET_TIMER行动,并指定计时器的细节,如使用下面定义的额外时间。

行动
ACTION_SET_TIMER
数据URI
没有
MIME类型
没有
附加功能
EXTRA_LENGTH
计时器的长度(秒)。
EXTRA_MESSAGE
自定义消息,以确定定时器。
EXTRA_SKIP_UI
一个布尔值,指定设置定时器,当响应应用程序是否应该跳过它的UI。如果为true,应用程序应该绕过任何确认的用户界面和简单的启动指定的定时器。

举例意图:

public  void startTimer ( String message ,  int seconds )  {   Intent intent =  new  Intent ( AlarmClock . ACTION_SET_TIMER )       . putExtra ( AlarmClock . EXTRA_MESSAGE , message )       . putExtra ( AlarmClock . EXTRA_LENGTH , seconds )       . putExtra ( AlarmClock . EXTRA_SKIP_UI ,  true );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }
注意:

为了调用ACTION_SET_TIMER意图,您的应用程序必须有SET_ALARM权限:

<使用许可权 的android:名称= “com.android.alarm.permission.SET_ALARM”  />

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.SET_TIMER"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

显示所有报警

要显示报警的列表,使用ACTION_SHOW_ALARMS行动。

虽然没有太多的应用程序将调用这个目的(它主要由系统的应用程序),它表现为一个闹钟任何应用程序应实现此意图过滤器,并显示当前报警的列表回应。

注:此意图是在Android 4.4系统(API级别19)补充道。

行动
ACTION_SHOW_ALARMS
数据URI
没有
MIME类型
没有

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.SHOW_ALARMS"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

日历

添加日历事件

若要将新事件添加到用户的日历,使用ACTION_INSERT行动,并指定与数据URIEvents.CONTENT_URI。然后,您可以使用下列定义各种额外活动详情。

行动
ACTION_INSERT
数据URI
Events.CONTENT_URI
MIME类型
“vnd.android.cursor.dir /事件”
附加功能
EXTRA_EVENT_ALL_DAY
一个布尔值,指定是否这是一个全天事件。
EXTRA_EVENT_BEGIN_TIME
事件的开始时间(纪元以来的毫秒)。
EXTRA_EVENT_END_TIME
事件的结束时间(纪元以来的毫秒)。
标题
该事件的标题。
描述
事件描述。
EVENT_LOCATION
该事件的位置。
EXTRA_EMAIL
以逗号分隔的电子邮件地址列表指定的受邀者。

更多活动详情可通过在中定义的常量指定CalendarContract.EventsColumns类。

举例意图:

public  void addEvent ( String title ,  String location ,  Calendar  begin ,  Calendar  end )  {   Intent intent =  new  Intent ( Intent . ACTION_INSERT )       . setData ( Events . CONTENT_URI )       . putExtra ( Events . TITLE , title )       . putExtra ( Events . EVENT_LOCATION , location )       . putExtra ( CalendarContract . EXTRA_EVENT_BEGIN_TIME ,  begin )       . putExtra ( CalendarContract . EXTRA_EVENT_END_TIME ,  end );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.INSERT"  />     <data  android:mimeType = "vnd.android.cursor.dir/event"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

相机

拍摄图片或视频,并将其返回

要打开相机应用和接收所产生的照片或视频,使用ACTION_IMAGE_CAPTUREACTION_VIDEO_CAPTURE行动。同时指定的URI位置您希望相机保存照片或视频,在EXTRA_OUTPUT额外费用。

行动
ACTION_IMAGE_CAPTUREACTION_VIDEO_CAPTURE
数据URI方案
没有
MIME类型
没有
附加功能
EXTRA_OUTPUT
该URI位置,摄像头应用程序应保存照片或视频文件(作为一个 开放的对象)。

当相机应用成功返回集中到你的活动(您的应用程序接收到的onActivityResult()回调),你可以访问你用指定的URI中的照片或视频EXTRA_OUTPUT值。

注意:当您使用ACTION_IMAGE_CAPTURE来拍摄照片,相机还可以返回结果中的照片的复印件缩小(缩略图)意图,保存为一个位图中提及的额外字段“数据”

举例意图:

static  final  int REQUEST_IMAGE_CAPTURE =  1 ; static  final  Uri mLocationForPhotos ; public  void capturePhoto ( String targetFilename )  {   Intent intent =  new  Intent ( MediaStore . ACTION_IMAGE_CAPTURE );   intent . putExtra ( MediaStore . EXTRA_OUTPUT ,       Uri . withAppendedPath ( mLocationForPhotos , targetFilename ));   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivityForResult ( intent , REQUEST_IMAGE_CAPTURE );   } } @Override protected  void onActivityResult ( int requestCode ,  int resultCode ,  Intent data )  {   if  ( requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK )  {     Bitmap thumbnail = data . getParcelable ( "data" );     //做其他工作,保存在mLocationForPhotos全尺寸的照片    ...   } }

有关如何使用此意图拍摄照片,包括如何建立一个适当的详细信息,乌里为输出位置,阅读拍照简单或拍摄视频简单。

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.media.action.IMAGE_CAPTURE"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

在处理这个意图,您的活动应该检查EXTRA_OUTPUT传入额外的意图,然后保存所拍摄的图像或视频在通过额外指定的位置,并调用的setResult()意向,其中包括在名为额外的压缩缩略图“数据“

在静止图像模式下启动相机应用


行动
要打开静态图像模式的相机应用程序,使用INTENT_ACTION_STILL_IMAGE_CAMERA行动。

INTENT_ACTION_STILL_IMAGE_CAMERA
数据URI方案
没有
MIME类型
没有
附加功能
没有

举例意图:

public  void capturePhoto ()  {   Intent intent =  new  Intent ( MediaStore . INTENT_ACTION_STILL_IMAGE_CAMERA );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivityForResult ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.media.action.STILL_IMAGE_CAMERA"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

开始在视频模式下相机应用


行动
要打开视频模式的相机应用程序,使用INTENT_ACTION_VIDEO_CAMERA行动。

INTENT_ACTION_VIDEO_CAMERA
数据URI方案
没有
MIME类型
没有
附加功能
没有

举例意图:

public  void capturePhoto ()  {   Intent intent =  new  Intent ( MediaStore . INTENT_ACTION_VIDEO_CAMERA );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivityForResult ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.media.action.VIDEO_CAMERA"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

联系人/联系人应用

选择一个联系人

让用户选择一个联系人,并提供给所有的联系人信息,您的应用程序访问,请使用ACTION_PICK行动,并指定MIME类型Contacts.CONTENT_TYPE

结果意向发送到您的onActivityResult()回调包含内容:URI指向选定的联系人。响应授予您的应用程序的临时权限读取用的接触联系提供API,即使你的应用程序不包含READ_CONTACTS许可。

提示:如果您需要访问只是一段特定的联系信息,如电话号码或电子邮件地址,而不是看到有关如何下一节选择特定的联系人数据。

行动
ACTION_PICK
数据URI方案
没有
MIME类型
Contacts.CONTENT_TYPE

举例意图:

static  final  int REQUEST_SELECT_CONTACT =  1 ; public  void selectContact ()  {   Intent intent =  new  Intent ( Intent . ACTION_PICK );   intent . setType ( ContactsContract . Contacts . CONTENT_TYPE );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivityForResult ( intent , REQUEST_SELECT_CONTACT );   } } @Override protected  void onActivityResult ( int requestCode ,  int resultCode ,  Intent data )  {   if  ( requestCode == REQUEST_SELECT_CONTACT && resultCode == RESULT_OK )  {     Uri contactUri = data . getData ();     //做一些与contactUri选定联系人    ...   } }

有关如何获取联系方式,一旦你取得联系URI信息,请阅读获取详细的联系方式。记住,当你检索联系人URI与上面的意图,你并不需要READ_CONTACTS权限读取该联系人的详细信息。

选择特定的联系人数据

为了让用户选择一个联系人,信息的特定部分,如电话号码,电子邮件地址或其他数据类型,使用ACTION_PICK行动,并指定MIME类型下面列出的内容类型,如之一CommonDataKinds。 Phone.CONTENT_TYPE获取联系人的电话号码。

如果需要从一个接触检索只有一种类型的数据,该技术具有CONTENT_TYPEContactsContract.CommonDataKinds类是比使用更有效Contacts.CONTENT_TYPE(如前一节中示出),因为结果为您提供直接访问使用时无需所需的数据以执行一个更复杂的查询联系人提供商。

结果意向发送到您的onActivityResult()回调包含内容:URI指向选定的联系人数据。响应授予您的应用程序的临时权限读取联系人数据,即使您的应用程序不包含READ_CONTACTS许可。

行动
ACTION_PICK
数据URI方案
没有
MIME类型
CommonDataKinds.Phone.CONTENT_TYPE
从电话号码的联系人挑选。
CommonDataKinds.Email.CONTENT_TYPE
从电子邮件地址的联系人挑选。
CommonDataKinds.StructuredPostal.CONTENT_TYPE
从邮政地址联系方式挑选。

许多其他的或者一个CONTENT_TYPE下值ContactsContract

举例意图:

静态 最终 INT REQUEST_SELECT_PHONE_NUMBER =  1 ; 公共 无效selectContact () {   //开始一个活动的用户选择从一个电话号码                         得到URI和查询内容提供商的电话                             如果返回的指针是有效的,拿到手机                           做一些与电话号码      ...     }   } }

查看联系人

要为一个已知的联系人显示详细信息,可以使用ACTION_VIEW行动,并指定了联系人内容:URI的意图数据。

有主要有两种方式来最初检索联系人的URI:

  • 使用由返回的接触URIACTION_PICK,在上一节中显示(这种方法不需要任何应用程序的权限)。
  • 直接访问所有联系人的列表,如在描述检索联系人列表(此方法需要READ_CONTACTS权限)。
行动
ACTION_VIEW
数据URI方案
内容:<URI>
MIME类型
没有。类型是从接触的URI推断。

举例意图:

public  void viewContact ( Uri contactUri )  {   Intent intent =  new  Intent ( Intent . ACTION_VIEW , contactUri );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

编辑现有的联系人

要编辑一个已知的接触,使用ACTION_EDIT动作,请用联系的内容:URI的意图数据,并且包括在常量指定额外任何已知的联系人信息ContactsContract.Intents.Insert

有主要有两种方式来最初检索联系人的URI:

  • 使用由返回的接触URIACTION_PICK,在上一节中显示(这种方法不需要任何应用程序的权限)。
  • 直接访问所有联系人的列表,如在描述检索联系人列表(此方法需要READ_CONTACTS权限)。
行动
ACTION_EDIT
数据URI方案
内容:<URI>
MIME类型
类型是从接触的URI推断。
附加功能
一个或多个定义的群众演员 ContactsContract.Intents.Insert这样你就可以填充的联系信息的字段。

举例意图:

public  void editContact ( Uri contactUri ,  String email )  {   Intent intent =  new  Intent ( Intent . ACTION_EDIT );   intent . setData ( contactUri );   intent . putExtra ( Intents . Insert . EMAIL , email );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

有关如何编辑联系人的详细信息,请参阅修改联系人使用意图。

插入联系人

要插入一个新的联系人,使用ACTION_INSERT行动,指定Contacts.CONTENT_TYPE作为MIME类型,并包括在指定的常量额外任何已知的联系人信息ContactsContract.Intents.Insert

行动
ACTION_INSERT
数据URI方案
没有
MIME类型
Contacts.CONTENT_TYPE
附加功能
一个或多个定义的群众演员 ContactsContract.Intents.Insert

举例意图:

public  void insertContact ( String name ,  String email )  {   Intent intent =  new  Intent ( Intent . ACTION_INSERT );   intent . setType ( Contacts . CONTENT_TYPE );   intent . putExtra ( Intents . Insert . NAME , name );   intent . putExtra ( Intents . Insert . EMAIL , email );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

有关如何插入联系人的详细信息,请参阅修改联系人使用意图。

电子邮件

撰写具有可选附件的电子邮件

要编写电子邮件,使用基于您是否会包含附件下列行为之一的,和包括电子邮件的详细信息,如收件人并受使用下面列出的额外的钥匙。

行动
ACTION_SENDTO(无附件)或 ACTION_SEND(一个附件)或 ACTION_SEND_MULTIPLE(多个附件)

数据URI方案
没有
MIME类型
“text / plain的”
“* / *”
附加功能
Intent.EXTRA_EMAIL
一个字符串数组所有“到”收件人的电子邮件地址。
Intent.EXTRA_CC
一个字符串数组,所有的“CC”的收件人的电子邮件地址。
Intent.EXTRA_BCC
一个字符串数组,所有的“密件抄送”收件人的电子邮件地址。
Intent.EXTRA_SUBJECT
字符串的邮件主题。
Intent.EXTRA_TEXT
一个字符串与电子邮件的正文。
Intent.EXTRA_STREAM
一个 开放的指向附件。如果使用的是 ACTION_SEND_MULTIPLE动作,这应该是不是一个 ArrayList中包含多个 开放的对象。

举例意图:

public  void composeEmail ( String [] addresses ,  String subject ,  Uri attachment )  {   Intent intent =  new  Intent ( Intent . ACTION_SEND );   intent . setType ( "*/*" );   intent . putExtra ( Intent . EXTRA_EMAIL , addresses );   intent . putExtra ( Intent . EXTRA_SUBJECT , subject );   intent . putExtra ( Intent . EXTRA_STREAM , attachment );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

如果你想确保你的意图是通过电子邮件应用程序(而不是其他短信或社交应用)才处理,然后用ACTION_SENDTO行动,包括“电子邮件地址:”数据方案。例如:

public  void composeEmail ( String [] addresses ,  String subject )  {   Intent intent =  new  Intent ( Intent . ACTION_SENDTO );   intent . setData ( Uri . parse ( "mailto:" ));  //只有电子邮件应用应如何处理this   intent . putExtra ( Intent . EXTRA_EMAIL , addresses );   intent . putExtra ( Intent . EXTRA_SUBJECT , subject );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.SEND"  />     <data  android:type = "*/*"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter>   <intent-filter>     <action  android:name = "android.intent.action.SENDTO"  />     <data  android:scheme = "mailto"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

文件存储

检索特定类型的文件

要请求用户选择一个文件,如文档或照片,并返回一个引用您的应用程序,使用ACTION_GET_CONTENT行动,并指定所需的MIME类型。引用返回到您的应用程序文件是短暂的,以您的活动目前的生命周期,因此,如果您要访问它后你必须导入一个副本,你可以在以后阅读。此意图也允许用户创建的过程中一个新的文件(例如,而不是选择现有照片时,用户可以捕捉与相机新照片)。

送到你的结果意图的onActivityResult()方法包括用一个URI指向文件数据。该URI可以是任何东西,如HTTP:URI,文件:URI或内容:URI。不过,如果你想选择的文件限制为只有那些从访问内容提供商(一个内容:URI),并且可作为一个文件流openFileDescriptor(),你应该添加CATEGORY_OPENABLE类别你的意图。

在Android 4.3(API级别18)和更高,还可以让用户通过添加选择多个文件EXTRA_ALLOW_MULTIPLE的意图,设置为。然后,您可以访问每个选定的文件在ClipData通过返回的对象()getClipData

行动
ACTION_GET_CONTENT
数据URI方案
没有
MIME类型
相应的文件类型,用户应选择的MIME类型。
附加功能
EXTRA_ALLOW_MULTIPLE
一个布尔宣布用户是否可以一次选择多个文件。
EXTRA_LOCAL_ONLY
声明返回的文件是否必须是可直接从设备,而不需要从远程服务下载的布尔值。
类别(可选)
CATEGORY_OPENABLE
为返回可被表示为文件流只有“开”的文件 openFileDescriptor()

例如意图得到一张照片:

static  final  int REQUEST_IMAGE_GET =  1 ; public  void selectImage ()  {   Intent intent =  new  Intent ( Intent . ACTION_GET_CONTENT );   intent . setType ( "image/*" );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivityForResult ( intent , REQUEST_IMAGE_GET );   } } @Override protected  void onActivityResult ( int requestCode ,  int resultCode ,  Intent data )  {   if  ( requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK )  {     Bitmap thumbnail = data . getParcelable ( "data" );     Uri fullPhotoUri = data . getData ();     //做保存在fullPhotoUri照片的工作    ......   } }

例如意图过滤器返回的照片:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.GET_CONTENT"  />     <data  android:type = "image/*"  />     <category  android:name = "android.intent.category.DEFAULT"  />     <!--可打开类声明,返回的文件是可访问      来自内容提供商supports OpenableColumns       and ContentResolver.openFileDescriptor() -->     <category  android:name = "android.intent.category.OPENABLE"  />   </intent-filter> </activity>

打开特定类型的文件

相反,检索,你必须导入到你的应用程序文件的副本(通过使用ACTION_GET_CONTENT动作),在Android 4.4或更高版本上运行时,可以改为请求打开使用的是由另一个应用程序管理的文件ACTION_OPEN_DOCUMENT行动,指定MIME类型。为了还允许用户,而不是创建一个新的文件,你的应用程序可以写入,使用ACTION_CREATE_DOCUMENT动作来代替。例如,而不是从现有的PDF文档中选择时,ACTION_CREATE_DOCUMENT意图允许用户选择他们想要创建一个新文件(管理文件的存储另一个应用程序内) -您的应用然后接收的地方可以在URI位置写入新文件。

而意图传递给你的onActivityResult()方法从ACTION_GET_CONTENT动作可以返回任何类型的URI,从结果意图ACTION_OPEN_DOCUMENTACTION_CREATE_DOCUMENT始终指定所选择的文件作为内容:URI这是由一个支持DocumentsProvider。您可以打开与文件openFileDescriptor(),并使用从列查询其详细信息DocumentsContract.Document

返回URI赋予您的应用程序的长期读取访问文件(也可能与写访问)。所以ACTION_OPEN_DOCUMENT动作是非常有用的(而不是使用ACTION_GET_CONTENT当你想读一个现有的文件不进行复制到你的应用程序,或当你想打开和就地编辑的文件)。

您也可以允许用户通过添加选择多个文件EXTRA_ALLOW_MULTIPLE的意图,设置为。如果用户选择只有一个项目,然后你可以从该项目的getData()。如果用户选择一个以上的项目,然后的getData()返回null,则必须改为从检索每个项目ClipData由返回的对象getClipData()

注意:您的意图必须指定一个MIME类型和必须申报CATEGORY_OPENABLE类别。如果合适的话,您可以通过添加MIME类型的数组与指定多个MIME类型EXTRA_MIME_TYPES外,如果你这样做,你必须设置在主MIME类型的setType(),以“* / *”

行动
ACTION_OPEN_DOCUMENTACTION_CREATE_DOCUMENT
数据URI方案
没有
MIME类型
相应的文件类型,用户应选择的MIME类型。
附加功能
EXTRA_MIME_TYPES
对应类型的应用请求文件的MIME类型的数组。当您使用此额外的,你必须设置在主MIME类型 的setType(),以 “* / *”
EXTRA_ALLOW_MULTIPLE
声明用户是否可以一次选择多个文件的布尔值。
EXTRA_TITLE
对于使用 ACTION_CREATE_DOCUMENT到指定初始文件名 ​​。
EXTRA_LOCAL_ONLY
声明返回的文件是否必须是可直接从设备,而不需要从远程服务下载的布尔值。
类别
CATEGORY_OPENABLE
为返回可被表示为文件流只有“开”的文件 openFileDescriptor()

例如意图得到一张照片:

           只有系统接收ACTION_OPEN_DOCUMENT,所以没必要                 做保存在fullPhotoUri全尺寸照片的工作    ...   } }

第三方应用程序不能真正与意图做出回应ACTION_OPEN_DOCUMENT行动。相反,系统接收到这个意图,并显示在一个统一的用户界面可从各种应用程序的所有文件。

为了提供您的应用程序的文件中的用户界面,并允许其他应用程序打开它们,你必须实现DocumentsProvider并包括一个意图过滤器PROVIDER_INTERFACE“android.content.action.DOCUMENTS_PROVIDER”)。例如:

<provider ...   android:grantUriPermissions = "true"   android:exported = "true"   android:permission = "android.permission.MANAGE_DOCUMENTS" >   <intent-filter>     <action  android:name = "android.content.action.DOCUMENTS_PROVIDER"  />   </intent-filter> </provider>

有关如何使您的应用程序从其他应用程序打开的管理文件的更多信息,请阅读存储访问架构指南。

本地操作

叫车


注:
在完成动作之前必须应用要求确认从用户。要叫出租车,使用ACTION_RESERVE_TAXI_RESERVATION行动。

行动
ACTION_RESERVE_TAXI_RESERVATION
数据URI
没有
MIME类型
没有
附加功能
没有

举例意图:

public  void callCar ()  {   Intent intent =  new  Intent ( ReserveIntents . ACTION_RESERVE_TAXI_RESERVATION );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "com.google.android.gms.actions.RESERVE_TAXI_RESERVATION"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

地图

在地图上显示的位置

打开一个地图,使用ACTION_VIEW动作,并与下面定义的方案之一中指定的意图数据的位置信息。

行动
ACTION_VIEW
数据URI方案
地理:纬度经度
显示在给定的经度和纬度的地图。

例如:“地球:47.6,-122.3”

地理:纬度经度?Z =缩放
显示在给定的经度的地图,并在一定的缩放级别纬度。1缩放级别显示了整个地球,在给定的中心 纬度经度。最高(最近)的缩放级别是23。

例如:“地球:47.6,-122.3 Z = 11”

地理:0,0 Q =纬度,经度(标签)
显示在给定的经度地图,并用字符串标签纬度。

例如:“地球:0,0 Q = 34.99,-106.61(宝物)”

地理:0,0 Q =我+街道+地址
显示“我的街道地址”的位置(可以是一个特定的地址或位置查询)。

例如:“地球:0,0 Q = 1600 +剧场+百汇%2C + CA”

注:在通过所有字符串地理URI必须进行编码。例如,该串第一和派克,西雅图应成为第1%20%26%20Pike%2C%20Seattle。该字符串中的空格可以与编码%20或加号(更换+)。

MIME类型
没有

举例意图:

public  void showMap ( Uri geoLocation )  {   Intent intent =  new  Intent ( Intent . ACTION_VIEW );   intent . setData ( geoLocation );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.VIEW"  />     <data  android:scheme = "geo"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

音乐或视频

播放媒体文件

播放音乐文件,使用ACTION_VIEW行动和意图的数据指定文件的URI位置。

行动
ACTION_VIEW
数据URI方案
文件:<URI>
内容:<URI>
HTTP:<网址>
MIME类型
“音频/ *”
“应用程序/ OGG”
“应用程序/ x-OGG”
“应用程序/ iTunes的”
或其他任何您的应用程序可能需要。

举例意图:

public  void playMedia ( Uri file )  {   Intent intent =  new  Intent ( Intent . ACTION_VIEW );   intent . setData ( file );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.VIEW"  />     <data  android:type = "audio/*"  />     <data  android:type = "application/ogg"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

基于搜索查询播放音乐


这个意图应该包括EXTRA_MEDIA_FOCUS串额外的,它指定了inteded搜索模式。例如,搜索模式可以指定搜索内容是一个艺术家姓名或歌曲名称。要播放基于搜索查询的音乐,使用INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH意图。一个应用程序可能会触发此意图响应用户的语音命令来播放音乐。这个意图接收应用程序执行其清单中搜索匹配现有的内容,以给定的查询,并开始播放这些内容。

行动
INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH
数据URI方案
没有
MIME类型
没有
附加功能
MediaStore.EXTRA_MEDIA_FOCUS(必填)

指示搜索模式(用户是否正在寻找一个特定的艺术家,专辑,歌曲或播放列表)。大多数搜索模式,采取额外的附加 ​​。例如,如果用户有兴趣听特定的歌曲,其目的可能有三个额外的附加 ​​:歌曲名称,艺术家和专辑。此意向支持的每个值以下搜索模式EXTRA_MEDIA_FOCUS

任何-“vnd.android.cursor.item / *”

播放任何音乐。接收应用程序应发挥基于一个聪明的选择,一些音乐如最后播放列表用户听。

额外的附加:

  • QUERY(必需) -空字符串。这个额外总是提供向后兼容性:现有的应用程序,不知道的搜索模式,可以处理这个意图为非结构化搜索。

非结构化-“vnd.android.cursor.item / *”

从非结构化搜索查询播放特定的歌曲,专辑或流派。应用程序可能会产生这种搜索模式时,他们无法识别用户想要收听的内容类型的意图。可能的情况下应用程序应该使用更具体的搜索模式。

额外的附加:

  • QUERY(必填) -包含的任意组合的字符串:艺术家,专辑,歌曲名称或流派。

流派-Audio.Genres.ENTRY_CONTENT_TYPE

播放特定类型的音乐。

额外的附加:

  • “android.intent.extra.genre”(必需) -流派。
  • QUERY(必需) -流派。这个额外总是提供向后兼容性:现有的应用程序,不知道的搜索模式,可以处理这个意图为非结构化搜索。

艺术家-Audio.Artists.ENTRY_CONTENT_TYPE

从特定艺术家播放音乐。

额外的附加:

  • EXTRA_MEDIA_ARTIST(必需) -艺术家。
  • “android.intent.extra.genre”-流派。
  • QUERY(必填) -包含艺术家或流派的任意组合的字符串。这个额外总是提供向后兼容性:现有的应用程序,不知道的搜索模式,可以处理这个意图为非结构化搜索。

专辑-Audio.Albums.ENTRY_CONTENT_TYPE

从一个特定的专辑播放音乐。

额外的附加:

  • EXTRA_MEDIA_ALBUM(必需) -专辑。
  • EXTRA_MEDIA_ARTIST-艺术家。
  • “android.intent.extra.genre”-流派。
  • QUERY(必填) -包含专辑或艺术家的任意组合的字符串。这个额外总是提供向后兼容性:现有的应用程序,不知道的搜索模式,可以处理这个意图为非结构化搜索。

-“vnd.android.cursor.item /音频”

播放特定的歌曲。

额外的附加:

  • EXTRA_MEDIA_ALBUM-专辑。
  • EXTRA_MEDIA_ARTIST-艺术家。
  • “android.intent.extra.genre”-流派。
  • EXTRA_MEDIA_TITLE(必需) -歌曲名。
  • QUERY(必填) -包含的任意组合的字符串:专辑,艺术家,流派或标题。这个额外总是提供向后兼容性:现有的应用程序,不知道的搜索模式,可以处理这个意图为非结构化搜索。

播放列表-Audio.Playlists.ENTRY_CONTENT_TYPE

播放特定的播放列表,或通过匹配额外附加的一些规定条件的播放列表。

额外的附加:

  • EXTRA_MEDIA_ALBUM-专辑。
  • EXTRA_MEDIA_ARTIST-艺术家。
  • “android.intent.extra.genre”-流派。
  • “android.intent.extra.playlist”-播放清单。
  • EXTRA_MEDIA_TITLE-该播放列表是根据歌曲名称。
  • QUERY(必填) -包含的任意组合的字符串:专辑,艺术家,流派,播放列表,或称号。这个额外总是提供向后兼容性:现有的应用程序,不知道的搜索模式,可以处理这个意图为非结构化搜索。

举例意图:

如果用户想从一个特定的艺术家听音乐,搜索应用程序可能会生成以下意图:

public  void playSearchArtist ( String artist )  {   Intent intent =  new  Intent ( MediaStore . INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH );   intent . putExtra ( MediaStore . EXTRA_MEDIA_FOCUS ,           MediaStore . Audio . Artists . ENTRY_CONTENT_TYPE );   intent . putExtra ( MediaStore . EXTRA_MEDIA_ARTIST , artist );   intent . putExtra ( SearchManager . QUERY , artist );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.media.action.MEDIA_PLAY_FROM_SEARCH"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

在处理这个意图,您的活动应该检查的价值EXTRA_MEDIA_FOCUS额外传入意图来确定搜索模式。一旦你的活动已经确定了搜索模式,它应该阅读额外的附加 ​​的值特定的搜索模式。有了这个信息,你的应用程序就可以执行其库存内的搜索播放相匹配的搜索查询的内容。例如:

                         一些群众演员取决于搜索可能无法使用                         确定搜索模式,并使用相应的临时演员    ,如果 mediaFocus ==   {       //'非结构化'搜索模式(向后                           “任何'搜索模式        playResumeLastPlaylist ();       }  其他 {         //'非结构化'的搜索                       '类型'的搜索                 “艺术家”搜索                 '相册'搜索模式      playAlbum 专辑艺术家);     }  否则 如果 mediaFocus 的compareTo “vnd.android.cursor.item /音频”  ==  0  {       //'歌'搜索                 “播放列表”搜索模式      playPlaylist 专辑艺术家流派播放列表标题);     }   } }

新注

创建笔记

要创建一个新的笔记,使用ACTION_CREATE_NOTE行动,并指定笔记的详细信息,如下面定义的主题和使用文本演员。

注:在完成动作之前必须应用要求确认从用户。

行动
ACTION_CREATE_NOTE
数据URI方案
没有
MIME类型
PLAIN_TEXT_TYPE
“* / *”
附加功能
EXTRA_NAME
一个字符串,指示标题或说明的主题。
EXTRA_TEXT
一个字符串,指示的说明文字。

举例意图:

public  void createNote ( String subject ,  String text )  {   Intent intent =  new  Intent ( NoteIntents . ACTION_CREATE_NOTE )       . putExtra ( NoteIntents . EXTRA_NAME , subject )       . putExtra ( NoteIntents . EXTRA_TEXT , text );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "com.google.android.gms.actions.CREATE_NOTE"  />     <category  android:name = "android.intent.category.DEFAULT"  />     <data  android:mimeType = ”*/*” >   </intent-filter> </activity>

电话

发起呼叫

打开手机应用程序,并拨打电话号码,使用ACTION_DIAL行动,并指定使用下面定义的URI方案的电话号码。当手机应用打开时,它显示的电话号码,但用户必须按下呼叫按钮开始通话。


ACTION_CALL操作需要您在添加CALL_PHONE权限您的清单文件:要直接拨打电话,使用ACTION_CALL行动,并指定使用下面定义的URI方案的电话号码。当手机应用打开时,它开始了电话;用户并不需要按呼叫按钮。

<使用许可权 的android:名称= “android.permission.CALL_PHONE”  />
行动
  • ACTION_DIAL-打开拨号器或手机应用程序。
  • ACTION_CALL-地点电话(需要CALL_PHONE许可)
数据URI方案
  • 联系电话:<电话号码>
  • 语音信箱:<电话号码>
MIME类型
没有

有效的电话号码是那些在所定义的IETF RFC 3966有效实例包括以下:

  • 联系电话:2125551212
  • 电话:(212)555 1212

手机的拨号善于正常化方案,如电话号码。所以描述的方案是不严格要求在Uri.parse()方法。但是,如果你还没有尝试过的计划或不确定是否可以处理,使用Uri.fromParts()方法来代替。

举例意图:

public  void dialPhoneNumber ( String phoneNumber )  {   Intent intent =  new  Intent ( Intent . ACTION_DIAL );   intent . setData ( Uri . parse ( "tel:"  + phoneNumber ));   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

搜索使用某特定应用



在您的应用程序进行语音搜索

为了支持你的应用程序的范围内搜索,与您的应用程序声明意图过滤器SEARCH_ACTION动作,如下面意图过滤的例子。

行动
“com.google.android.gms.actions.SEARCH_ACTION”
支持谷歌搜索查询现在。
附加功能
QUERY
包含搜索查询的字符串。

举例意图过滤器:

<activity  android:name = ".SearchActivity" >   <intent-filter>     <action  android:name = "com.google.android.gms.actions.SEARCH_ACTION" />     <category  android:name = "android.intent.category.DEFAULT" />   </intent-filter> </activity>

执行网络搜索

要启动网络搜索,使用ACTION_WEB_SEARCH行动,并指定要在搜索字符串SearchManager.QUERY额外费用。

行动
ACTION_WEB_SEARCH
数据URI方案
没有
MIME类型
没有
附加功能
SearchManager.QUERY
搜索字符串。

举例意图:

public  void searchWeb ( String query )  {   Intent intent =  new  Intent ( Intent . ACTION_SEARCH );   intent . putExtra ( SearchManager . QUERY , query );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

设置

打开设置的特定部分

要在您的应用程序要求用户更改某些设置,使用下面的意图行动,以打开设置界面相应的操作名称之一打开系统设置的屏幕。

行动
ACTION_SETTINGS
ACTION_WIRELESS_SETTINGS
ACTION_AIRPLANE_MODE_SETTINGS
ACTION_WIFI_SETTINGS
ACTION_APN_SETTINGS
ACTION_BLUETOOTH_SETTINGS
ACTION_DATE_SETTINGS
ACTION_LOCALE_SETTINGS
ACTION_INPUT_METHOD_SETTINGS
ACTION_DISPLAY_SETTINGS
ACTION_SECURITY_SETTINGS
ACTION_LOCATION_SOURCE_SETTINGS
ACTION_INTERNAL_STORAGE_SETTINGS
ACTION_MEMORY_CARD_SETTINGS

查看设置为其他设置屏幕可用文档。

数据URI方案
没有
MIME类型
没有

举例意图:

public  void openWifiSettings ()  {   Intent intent =  new  Intent ( Intent . ACTION_WIFI_SETTINGS );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

短信

缀以附件的短信/彩信

要启动SMS或MMS短信,使用下面的意图行动之一,并指定消息的详细信息,如电话号码,主题和邮件正文使用下面列出的额外的钥匙。

行动
ACTION_SENDTOACTION_SENDACTION_SEND_MULTIPLE

数据URI方案
短信:<PHONE_NUMBER>
smsto:<PHONE_NUMBER>
彩信:<PHONE_NUMBER>
mmsto:<PHONE_NUMBER>

所有这些方案的处理方式相同。

MIME类型
“text / plain的”
“图片/*”
“视频/*”
附加功能
“学科”
一种邮件主题的字符串(通常仅MMS)。
“SMS_BODY”
一个字符串文本消息。
EXTRA_STREAM
一个 开放的指向图像或视频附加。如果使用的是 ACTION_SEND_MULTIPLE动作,这个额外的应该是一个 ArrayList中开放的指点下到图像/视频附加。

举例意图:

public  void composeMmsMessage ( String message ,  Uri attachment )  {   Intent intent =  new  Intent ( Intent . ACTION_SENDTO );   intent . setType ( HTTP . PLAIN_TEXT_TYPE );   intent . putExtra ( "sms_body" , message );   intent . putExtra ( Intent . EXTRA_STREAM , attachment );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

如果你想确保你的意图是通过短信的应用程序(而不是其他电子邮件或社交应用程序)才处理,然后用ACTION_SENDTO行动,包括“smsto:”数据方案。例如:

public  void composeMmsMessage ( String message ,  Uri attachment )  {   Intent intent =  new  Intent ( Intent . ACTION_SEND );   intent . setData ( Uri . parse ( "smsto:" ));  //这可确保只有短信应用respond   intent . putExtra ( "sms_body" , message );   intent . putExtra ( Intent . EXTRA_STREAM , attachment );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<activity ... >   <intent-filter>     <action  android:name = "android.intent.action.SEND"  />     <data  android:type = "text/plain"  />     <data  android:type = "image/*"  />     <category  android:name = "android.intent.category.DEFAULT"  />   </intent-filter> </activity>

注:如果您正在开发的SMS / MMS短信应用程序,您必须实现意图过滤器对几个附加的行为,以便可作为默认的短信应用在Android 4.4及更高版本。欲了解更多信息,请阅读文档电话

网页浏览器

加载网页的网址


行动
要打开一个网页,使用ACTION_VIEW行动,并在意向数据指定Web URL。

ACTION_VIEW
数据URI方案
HTTP:<网址>
的https:<网址>
MIME类型
“text / plain的”
“text / html的”
“是application / xhtml + XML”
“应用程序/ vnd.wap.xhtml + XML”

举例意图:

public  void openWebPage ( String url )  {   Uri webpage =  Uri . parse ( url );   Intent intent =  new  Intent ( Intent . ACTION_VIEW , webpage );   if  ( intent . resolveActivity ( getPackageManager ())  !=  null )  {     startActivity ( intent );   } }

举例意图过滤器:

<活动... >   <意图过滤器>     <行动 机器人:名字= “android.intent.action.VIEW”  />     < -包括主机属性,如果你想你的应用程序响应!      只与您的应用程序的网域网址。                 可浏览的类别需要得到从网页链接。- >     <类 机器人:名字= “android.intent.category.BROWSABLE”  />   </意图过滤> </活动>

提示:如果您的Android应用程序提供了类似于你的网站的功能,包括指向你的网站的网址意图过滤器。然后,如果用户安装了您的应用程序,从电子邮件或其他网页指向你的网站打开你的Android应用程序,而不是你的网页链接。

验证了Android调试桥意图

要验证您的应用程序响应你想要支持的意图,则可以使用ADB工具火特定意图:

  1. 设置Android设备的开发,或者使用虚拟设备。
  2. 安装一个版本的应用程序的处理要支持的意图。
  3. 消防使用意图ADB
    亚行的shell时开始-a <ACTION> -t <MIME_TYPE> -d <DATA> \   -e <EXTRA_NAME> <EXTRA_VALUE> -n <活动>

    例如:

    亚行的shell时开始-a android.intent.action.DIAL \   -d电话:555-5555 -n org.example.MyApp / .MyActivity
  4. 如果定义所需的意图过滤器,您的应用程序应该处理这个意图。

欲了解更多信息,请参见ADB Shell命令。

由谷歌解雇现在的意图

谷歌现在认识了很多语音命令和火灾意图他们。因此,用户可以启动应用程序与谷歌一现在,语音命令,如果您的应用程序声明相应的意图过滤器。例如,如果您的应用程序可以设置闹钟和你对应的意图过滤器添加到您的清单文件,谷歌现在允许用户选择你的应用程序时,他们要求设置闹钟,如图1。

图1.谷歌现在可以让用户从支持一个给定的动作安装的应用程序选择。

谷歌现在认识到表1中列出有关声明的每个意图过滤器的详细信息的行动声控命令,请单击操作说明。

表1.由谷歌现在公认的语音命令(谷歌搜索应用3.6版)。

类别 详细信息和示例 操作名称
报警

设置闹钟

  • “设置警报7 AM”
AlarmClock.ACTION_SET_ALARM

设置计时器

  • “设置一个计时器5分钟”
AlarmClock.ACTION_SET_TIMER
通讯

呼叫号码

  • “呼555-5555”
  • “呼叫鲍勃”
  • “电话语音信箱”
Intent.ACTION_CALL
本地

预订汽车

  • “叫我车”
  • “我订了一辆出租车”
ReserveIntents
.ACTION_RESERVE_TAXI_RESERVATION
媒体

从搜索播放音乐

  • “玩迈克尔·杰克逊比莉珍”
MediaStore
.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH

拍照

  • “拍照”
MediaStore
.INTENT_ACTION_STILL_IMAGE_CAMERA

录制视频

  • “录制视频”
MediaStore
.INTENT_ACTION_VIDEO_CAMERA
搜索

搜索使用某特定应用

  • “寻找猫的视频
    在myvideoapp”
“com.google.android.gms.actions
.SEARCH_ACTION”
网页浏览器

打开网址

  • “开放example.com”
Intent.ACTION_VIEW

.

更多相关文章

  1. notification android原生消息通知代码详解
  2. android SharePreference适用任何基本类型工具类
  3. android 7.0 user版本调试方法
  4. android 程序间跳转
  5. Android获取应用程序名称(ApplicationName)
  6. ant build.xml yguard混淆JAVA
  7. Android隐式意图
  8. Android(安卓)目录选择器
  9. 在子线程中更新UI(后台服务)

随机推荐

  1. 携程万台规模容器云平台运维管理实践
  2. 数据分析的基石-真实世界
  3. 降级?限流?程序员双十一过后如何5元花3天?
  4. 设计思想赏析-分布式id生成算法-雪花算法
  5. 设计思想赏析-基因算法
  6. 第一课 vscode软件和常用插件的下载安装
  7. 编辑器安装与emmet语法
  8. Visual Studio Code 编辑器
  9. 超强大工具!快速下载安装vscode和必备插件
  10. 硬盘提示函数不正确怎么找回