Legalsounds Streams Email Resources Apps Arts Messaging Communities Wireles
An intent allows you to start an activeness in another app by describing a simple action yous'd like to perform (such every bit "view a map" or "take a movie") in an Intent object. This blazon of intent is called an implicit intent because it does not specify the app component to outset, but instead specifies an action and provides some data with which to perform the action.
When y'all phone call startActivity() or startActivityForResult() and pass information technology an implicit intent, the arrangement resolves the intent to an app that can handle the intent and starts its corresponding Activity. If there's more than than one app that tin handle the intent, the system presents the user with a dialog to option which app to utilize.
This page describes several implicit intents that y'all tin can use to perform common actions, organized past the type of app that handles the intent. Each section too shows how you can create an intent filter to annunciate your app's ability to perform the same action.
Caution: If in that location are no apps on the device that can receive the implicit intent, your app will crash when it calls startActivity(). To kickoff verify that an app exists to receive the intent, call resolveActivity() on your Intent object. If the event is non-nada, in that location is at least one app that tin can handle the intent and it's safe to phone call startActivity(). If the event is null, you should non employ the intent and, if possible, you should disable the characteristic that invokes the intent.
If y'all're not familiar with how to create intents or intent filters, y'all should first read Intents and Intent Filters.
To learn how to fire the intents listed on this page from your development host, encounter Verify Intents with the Android Debug Bridge.
Google Vox Actions
Google Voice Actions fires some of the intents listed on this page in response to phonation commands. For more than information, run into Intents fired by Google Voice Actions.
Alarm Clock
Create an alarm
Google Voice Deportment
- "set an alarm for vii am"
To create a new alarm, apply the ACTION_SET_ALARM action and specify alarm details such every bit the time and message using extras defined below.
Annotation: Only the hour, minutes, and bulletin extras are available in Android two.three (API level ix) and lower. The other extras were added in afterward versions of the platform.
- Action
-
ACTION_SET_ALARM - Information URI
- None
- MIME Type
- None
- Extras
-
-
EXTRA_HOUR - The hour for the alarm.
-
EXTRA_MINUTES - The minutes for the warning.
-
EXTRA_MESSAGE - A custom message to place the warning.
-
EXTRA_DAYS - An
ArrayListincluding each week twenty-four hour period on which this alert should be repeated. Each day must be alleged with an integer from theAgendaform such every bitMon.For a i-time alarm, do not specify this actress.
-
EXTRA_RINGTONE - A
content:URI specifying a ringtone to utilise with the alarm, orVALUE_RINGTONE_SILENTfor no ringtone.To utilize the default ringtone, practise 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 warning. If true, the app should bypass whatsoever confirmation UI and simply set the specified alert.
-
Example intent:
Kotlin
fun createAlarm(message: String, hour: Int, minutes: Int) { val intent = Intent(AlarmClock.ACTION_SET_ALARM).apply { putExtra(AlarmClock.EXTRA_MESSAGE, message) putExtra(AlarmClock.EXTRA_HOUR, hour) putExtra(AlarmClock.EXTRA_MINUTES, minutes) } if (intent.resolveActivity(packageManager) != zip) { startActivity(intent) } } Java
public void createAlarm(String message, int hr, int minutes) { Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM) .putExtra(AlarmClock.EXTRA_MESSAGE, bulletin) .putExtra(AlarmClock.EXTRA_HOUR, hour) .putExtra(AlarmClock.EXTRA_MINUTES, minutes); if (intent.resolveActivity(getPackageManager()) != goose egg) { startActivity(intent); } } Notation:
In society to invoke the ACTION_SET_ALARM intent, your app must take the SET_ALARM permission:
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
Instance intent filter:
<activity ...> <intent-filter> <activeness android:name="android.intent.activity.SET_ALARM" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activeness>
Create a timer
Google Vocalisation Deportment
- "set timer for 5 minutes"
To create a countdown timer, employ the ACTION_SET_TIMER action and specify timer details such equally the duration using extras defined below.
Annotation: This intent was added in Android 4.4 (API level 19).
- Activity
-
ACTION_SET_TIMER - Data URI
- None
- MIME Type
- None
- Extras
-
-
EXTRA_LENGTH - The length of the timer in seconds.
-
EXTRA_MESSAGE - A custom bulletin 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 featherbed whatsoever confirmation UI and simply start the specified timer.
-
Example intent:
Kotlin
fun startTimer(bulletin: String, seconds: Int) { val intent = Intent(AlarmClock.ACTION_SET_TIMER).apply { putExtra(AlarmClock.EXTRA_MESSAGE, message) putExtra(AlarmClock.EXTRA_LENGTH, seconds) putExtra(AlarmClock.EXTRA_SKIP_UI, true) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Coffee
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()) != naught) { startActivity(intent); } } Note:
In gild to invoke the ACTION_SET_TIMER intent, your app must have the SET_ALARM permission:
<uses-permission android:name="com.android.warning.permission.SET_ALARM" />
Example intent filter:
<action ...> <intent-filter> <action android:name="android.intent.action.SET_TIMER" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Show all alarms
To testify the list of alarms, use the ACTION_SHOW_ALARMS action.
Although non many apps will invoke this intent (it's primarily used past organization apps), whatsoever app that behaves equally an warning clock should implement this intent filter and respond past showing the list of current alarms.
Note: This intent was added in Android iv.4 (API level 19).
- Action
-
ACTION_SHOW_ALARMS - Data URI
- None
- MIME Type
- None
Instance intent filter:
<activity ...> <intent-filter> <activeness android:name="android.intent.action.SHOW_ALARMS" /> <category android:proper name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Calendar
Add a agenda issue
To add a new event to the user'southward calendar, employ the ACTION_INSERT action and specify the data URI with Events.CONTENT_URI. Yous tin can and 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 upshot.
-
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 championship.
-
DESCRIPTION - The event description.
-
EVENT_LOCATION - The event location.
-
EXTRA_EMAIL - A comma-separated list of e-mail addresses that specify the invitees.
Many more consequence details can be specified using the constants divers in the
CalendarContract.EventsColumnsclass. -
Example intent:
Kotlin
fun addEvent(title: String, location: String, begin: Long, end: Long) { val intent = Intent(Intent.ACTION_INSERT).use { information = Events.CONTENT_URI putExtra(Events.TITLE, championship) putExtra(Events.EVENT_LOCATION, location) putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin) putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end) } if (intent.resolveActivity(packageManager) != zilch) { startActivity(intent) } } Java
public void addEvent(String championship, String location, long brainstorm, long end) { Intent intent = new Intent(Intent.ACTION_INSERT) .setData(Events.CONTENT_URI) .putExtra(Events.TITLE, championship) .putExtra(Events.EVENT_LOCATION, location) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end); if (intent.resolveActivity(getPackageManager()) != nada) { startActivity(intent); } } Instance intent filter:
<activeness ...> <intent-filter> <action android:name="android.intent.action.INSERT" /> <data android:mimeType="vnd.android.cursor.dir/event" /> <category android:proper name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Camera
Capture a flick or video and return information technology
To open up a camera app and receive the resulting photograph or video, use the ACTION_IMAGE_CAPTURE or ACTION_VIDEO_CAPTURE action. As well specify the URI location where you'd like the camera to salvage the photo or video, in the EXTRA_OUTPUT extra.
- Action
-
ACTION_IMAGE_CAPTUREor
ACTION_VIDEO_CAPTURE - Information URI Scheme
- None
- MIME Blazon
- None
- Extras
-
-
EXTRA_OUTPUT - The URI location where the photographic camera app should relieve the photo or video file (as a
Uriobject).
-
When the camera app successfully returns focus to your activeness (your app receives the onActivityResult() callback), yous can access the photo or video at the URI you lot specified with the EXTRA_OUTPUT value.
Annotation: When you utilise ACTION_IMAGE_CAPTURE to capture a photo, the photographic camera may also return a downscaled copy (a thumbnail) of the photo in the result Intent, saved as a Bitmap in an extra field named "data".
Example intent:
Kotlin
const val REQUEST_IMAGE_CAPTURE = 1 val locationForPhotos: Uri = ... fun capturePhoto(targetFilename: String) { val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).utilize { putExtra(MediaStore.EXTRA_OUTPUT, Uri.withAppendedPath(locationForPhotos, targetFilename)) } if (intent.resolveActivity(packageManager) != nil) { startActivityForResult(intent, REQUEST_IMAGE_CAPTURE) } } override fun onActivityResult(requestCode: Int, resultCode: Int, information: Intent) { if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) { val thumbnail: Bitmap = information.getParcelableExtra("information") // Practice other work with total size photograph saved in locationForPhotos ... } } Java
static last int REQUEST_IMAGE_CAPTURE = 1; static final Uri locationForPhotos; public void capturePhoto(String targetFilename) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.withAppendedPath(locationForPhotos, targetFilename)); if (intent.resolveActivity(getPackageManager()) != naught) { 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 = information.getParcelableExtra("data"); // Practise other work with full size photo saved in locationForPhotos ... } } For more information near how to use this intent to capture a photo, including how to create an appropriate Uri for the output location, read Taking Photos Simply or Taking Videos Simply.
Instance intent filter:
<activity ...> <intent-filter> <action android:name="android.media.action.IMAGE_CAPTURE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
When treatment this intent, your activity should check for the EXTRA_OUTPUT extra in the incoming Intent, then relieve the captured image or video at the location specified past that extra and telephone call setResult() with an Intent that includes a compressed thumbnail in an actress named "data".
Start a camera app in still paradigm mode
Google Vocalism Deportment
- "accept a picture"
To open a photographic camera app in nevertheless prototype mode, use the INTENT_ACTION_STILL_IMAGE_CAMERA activeness.
- Action
-
INTENT_ACTION_STILL_IMAGE_CAMERA - Data URI Scheme
- None
- MIME Blazon
- None
- Extras
- None
Instance intent:
Kotlin
fun capturePhoto() { val intent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA) if (intent.resolveActivity(packageManager) != null) { startActivityForResult(intent, REQUEST_IMAGE_CAPTURE) } } Coffee
public void capturePhoto() { Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } } Instance intent filter:
<activity ...> <intent-filter> <action android:name="android.media.activity.STILL_IMAGE_CAMERA" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activeness>
Kickoff a camera app in video mode
Google Voice Actions
- "tape a video"
To open up a camera app in video mode, utilise the INTENT_ACTION_VIDEO_CAMERA action.
- Action
-
INTENT_ACTION_VIDEO_CAMERA - Data URI Scheme
- None
- MIME Type
- None
- Extras
- None
Instance intent:
Kotlin
fun capturePhoto() { val intent = Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA) if (intent.resolveActivity(packageManager) != null) { startActivityForResult(intent, REQUEST_IMAGE_CAPTURE) } } Java
public void capturePhoto() { Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } } Example intent filter:
<activity ...> <intent-filter> <activeness android:name="android.media.action.VIDEO_CAMERA" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Select a contact
To have the user select a contact and provide your app access to all the contact data, use the ACTION_PICK action and specify the MIME type to Contacts.CONTENT_TYPE.
The result Intent delivered to your onActivityResult() callback contains the content: URI pointing to the selected contact. The response grants your app temporary permissions to read that contact using the Contacts Provider API even if your app does not include the READ_CONTACTS permission.
Tip: If you need access to only a specific piece of contact data, such as a phone number or email address, instead run into the next section about how to select specific contact data.
- Action
-
ACTION_PICK - Data URI Scheme
- None
- MIME Type
-
Contacts.CONTENT_TYPE
Example intent:
Kotlin
const val REQUEST_SELECT_CONTACT = ane fun selectContact() { val intent = Intent(Intent.ACTION_PICK).apply { type = ContactsContract.Contacts.CONTENT_TYPE } if (intent.resolveActivity(packageManager) != null) { startActivityForResult(intent, REQUEST_SELECT_CONTACT) } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { if (requestCode == REQUEST_SELECT_CONTACT && resultCode == RESULT_OK) { val contactUri: Uri = data.information // Do something with the selected contact at contactUri //... } } Java
static last 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(); // Do something with the selected contact at contactUri ... } } For information about how to retrieve contact details once you take the contact URI, read Retrieving Details for a Contact.
When you recall the contact URI using the above intent, yous generally don't need the READ_CONTACTS permission to read basic details for that contact, such equally brandish proper name and whether the contact is starred. However, if you're trying to read more specific data about a given contact—such equally their phone number or email accost—you demand the READ_CONTACTS permission.
Select specific contact data
To accept the user select a specific piece of information from a contact, such every bit a phone number, electronic mail address, or other information blazon, employ the ACTION_PICK action and specify the MIME blazon to one of the content types listed below, such as CommonDataKinds.Phone.CONTENT_TYPE to get the contact's phone number.
Note: In many cases, your app needs to have the READ_CONTACTS permission in social club to view specific information about a detail contact.
If y'all need to think only one type of data from a contact, this technique with a CONTENT_TYPE from the ContactsContract.CommonDataKinds classes is more efficient than using the Contacts.CONTENT_TYPE (as shown in the previous section) considering the outcome provides you direct access to the desired data without requiring you to perform a more complex query to Contacts Provider.
The result Intent delivered to your onActivityResult() callback contains the content: 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 the READ_CONTACTS permission.
- Activity
-
ACTION_PICK - Data URI Scheme
- None
- MIME Type
-
-
CommonDataKinds.Phone.CONTENT_TYPE - Choice from contacts with a phone number.
-
CommonDataKinds.Electronic mail.CONTENT_TYPE - Choice from contacts with an electronic mail address.
-
CommonDataKinds.StructuredPostal.CONTENT_TYPE - Pick from contacts with a postal accost.
Or one of many other
CONTENT_TYPEvalues underContactsContract. -
Example intent:
Kotlin
const val REQUEST_SELECT_PHONE_NUMBER = 1 fun selectContact() { // First an activity for the user to pick a phone number from contacts val intent = Intent(Intent.ACTION_PICK).utilize { type = CommonDataKinds.Phone.CONTENT_TYPE } if (intent.resolveActivity(packageManager) != null) { startActivityForResult(intent, REQUEST_SELECT_PHONE_NUMBER) } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { if (requestCode == REQUEST_SELECT_PHONE_NUMBER && resultCode == Activity.RESULT_OK) { // Go the URI and query the content provider for the telephone number val contactUri: Uri = data.data val project: Assortment<String> = arrayOf(CommonDataKinds.Telephone.NUMBER) contentResolver.query(contactUri, projection, nada, null, null).use { cursor -> // If the cursor returned is valid, get the phone number if (cursor.moveToFirst()) { val numberIndex = cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER) val number = cursor.getString(numberIndex) // Practise something with the telephone number ... } } } } Java
static last int REQUEST_SELECT_PHONE_NUMBER = 1; public void selectContact() { // Start an activeness 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()) != zilch) { startActivityForResult(intent, REQUEST_SELECT_PHONE_NUMBER); } } @Override protected 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 Cord[]{CommonDataKinds.Phone.NUMBER}; Cursor cursor = getContentResolver().query(contactUri, projection, nil, zero, null); // If the cursor returned is valid, get the telephone number if (cursor != zero && cursor.moveToFirst()) { int numberIndex = cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER); String number = cursor.getString(numberIndex); // Practice something with the phone number //... } } } View a contact
To display the details for a known contact, employ the ACTION_VIEW activity and specify the contact with a content: URI as the intent data.
There are primarily two ways to initially retrieve the contact's URI:
- Use the contact URI returned by the
ACTION_PICK, shown in the previous section (this arroyo does not require any app permissions). - Access the list of all contacts directly, as described in Retrieving a Listing of Contacts (this approach requires the
READ_CONTACTSpermission).
- Action
-
ACTION_VIEW - Information URI Scheme
-
content:<URI> - MIME Blazon
- None. The type is inferred from contact URI.
Case intent:
Kotlin
fun viewContact(contactUri: Uri) { val intent = Intent(Intent.ACTION_VIEW, contactUri) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void viewContact(Uri contactUri) { Intent intent = new Intent(Intent.ACTION_VIEW, contactUri); if (intent.resolveActivity(getPackageManager()) != zero) { startActivity(intent); } } Edit an existing contact
To edit a known contact, use the ACTION_EDIT activity, specify the contact with a content: URI as the intent data, and include any known contact information in extras specified by constants in ContactsContract.Intents.Insert.
There are primarily 2 ways to initially retrieve the contact URI:
- Apply the contact URI returned by the
ACTION_PICK, shown in the previous department (this arroyo does not crave any app permissions). - Access the list of all contacts directly, every bit described in Retrieving a List of Contacts (this approach requires the
READ_CONTACTSpermission).
- Activity
-
ACTION_EDIT - Information URI Scheme
-
content:<URI> - MIME Blazon
- The blazon is inferred from contact URI.
- Extras
- One or more than of the extras defined in
ContactsContract.Intents.Insertso you lot can populate fields of the contact details.
Example intent:
Kotlin
fun editContact(contactUri: Uri, email: String) { val intent = Intent(Intent.ACTION_EDIT).apply { data = contactUri putExtra(ContactsContract.Intents.Insert.EMAIL, e-mail) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void editContact(Uri contactUri, String e-mail) { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setData(contactUri); intent.putExtra(Intents.Insert.Electronic mail, email); if (intent.resolveActivity(getPackageManager()) != nil) { startActivity(intent); } } For more information well-nigh how to edit a contact, read Modifying Contacts Using Intents.
Insert a contact
To insert a new contact, use the ACTION_INSERT activeness, specify Contacts.CONTENT_TYPE as the MIME type, and include any known contact data in extras specified by constants in ContactsContract.Intents.Insert.
- Action
-
ACTION_INSERT - Data URI Scheme
- None
- MIME Type
-
Contacts.CONTENT_TYPE - Extras
- One or more than of the extras divers in
ContactsContract.Intents.Insert.
Example intent:
Kotlin
fun insertContact(name: Cord, electronic mail: String) { val intent = Intent(Intent.ACTION_INSERT).apply { type = ContactsContract.Contacts.CONTENT_TYPE putExtra(ContactsContract.Intents.Insert.NAME, name) putExtra(ContactsContract.Intents.Insert.EMAIL, email) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void insertContact(String name, Cord e-mail) { Intent intent = new Intent(Intent.ACTION_INSERT); intent.setType(Contacts.CONTENT_TYPE); intent.putExtra(Intents.Insert.NAME, name); intent.putExtra(Intents.Insert.Electronic mail, email); if (intent.resolveActivity(getPackageManager()) != naught) { startActivity(intent); } } For more information nigh how to insert a contact, read Modifying Contacts Using Intents.
Compose an email with optional attachments
To compose an electronic mail, utilise one of the below actions based on whether y'all'll include attachments, and include email details such every bit the recipient and bailiwick using the extra keys listed below.
- Action
-
ACTION_SENDTO(for no attachment) or
ACTION_SEND(for ane zipper) or
ACTION_SEND_MULTIPLE(for multiple attachments) - Data URI Scheme
- None
- MIME Blazon
-
-
"text/manifestly" -
"*/*"
-
- Extras
-
-
Intent.EXTRA_EMAIL - A cord array of all "To" recipient electronic mail addresses.
-
Intent.EXTRA_CC - A string array of all "CC" recipient email addresses.
-
Intent.EXTRA_BCC - A string assortment of all "BCC" recipient email addresses.
-
Intent.EXTRA_SUBJECT - A string with the email bailiwick.
-
Intent.EXTRA_TEXT - A string with the torso of the e-mail.
-
Intent.EXTRA_STREAM - A
Uripointing to the attachment. If using theACTION_SEND_MULTIPLEaction, this should instead be anArrayListcontaining multipleUriobjects.
-
Example intent:
Kotlin
fun composeEmail(addresses: Array<String>, discipline: Cord, attachment: Uri) { val intent = Intent(Intent.ACTION_SEND).apply { type = "*/*" putExtra(Intent.EXTRA_EMAIL, addresses) putExtra(Intent.EXTRA_SUBJECT, subject) putExtra(Intent.EXTRA_STREAM, zipper) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void composeEmail(Cord[] addresses, String subject field, Uri attachment) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); intent.putExtra(Intent.EXTRA_EMAIL, addresses); intent.putExtra(Intent.EXTRA_SUBJECT, field of study); intent.putExtra(Intent.EXTRA_STREAM, zipper); if (intent.resolveActivity(getPackageManager()) != zero) { startActivity(intent); } } If you lot desire to ensure that your intent is handled only past an electronic mail app (and not other text messaging or social apps), then utilize the ACTION_SENDTO action and include the "mailto:" information scheme. For example:
Kotlin
fun composeEmail(addresses: Array<Cord>, subject: String) { val intent = Intent(Intent.ACTION_SENDTO).use { data = Uri.parse("mailto:") // only email apps should handle this putExtra(Intent.EXTRA_EMAIL, addresses) putExtra(Intent.EXTRA_SUBJECT, subject area) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void composeEmail(String[] addresses, Cord discipline) { Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // simply email apps should handle this intent.putExtra(Intent.EXTRA_EMAIL, addresses); intent.putExtra(Intent.EXTRA_SUBJECT, field of study); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } Case intent filter:
<activity ...> <intent-filter> <action android:name="android.intent.action.SEND" /> <data android:blazon="*/*" /> <category android:proper noun="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <activity android:name="android.intent.action.SENDTO" /> <data android:scheme="mailto" /> <category android:proper name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
File Storage
Retrieve a specific type of file
To asking that the user select a file such every bit a document or photograph and render a reference to your app, use the ACTION_GET_CONTENT action and specify your desired MIME blazon. The file reference returned to your app is transient to your activity's current lifecycle, and then if you want to access it later you must import a copy that you can read later. This intent too allows the user to create a new file in the process (for case, instead of selecting an existing photograph, the user tin capture a new photograph with the camera).
The event intent delivered to your onActivityResult() method includes data with a URI pointing to the file. The URI could be annihilation, such as an http: URI, file: URI, or content: URI. However, if you'd similar to restrict selectable files to only those that are accessible from a content provider (a content: URI) and that are available as a file stream with openFileDescriptor(), yous should add together the CATEGORY_OPENABLE category to your intent.
On Android iv.3 (API level 18) and higher, yous tin can also allow the user to select multiple files by adding EXTRA_ALLOW_MULTIPLE to the intent, prepare to true. You lot can then access each of the selected files in a ClipData object returned past getClipData().
- Action
-
ACTION_GET_CONTENT - Information URI Scheme
- None
- MIME Type
- The MIME blazon corresponding to the file blazon 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 render just "openable" files that can be represented as a file stream with
openFileDescriptor().
-
Example intent to get a photo:
Kotlin
const val REQUEST_IMAGE_GET = 1 fun selectImage() { val intent = Intent(Intent.ACTION_GET_CONTENT).apply { blazon = "image/*" } if (intent.resolveActivity(packageManager) != null) { startActivityForResult(intent, REQUEST_IMAGE_GET) } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { if (requestCode == REQUEST_IMAGE_GET && resultCode == Activity.RESULT_OK) { val thumbnail: Bitmap = data.getParcelableExtra("data") val fullPhotoUri: Uri = data.data // Do work with photo saved at fullPhotoUri ... } } Coffee
static final int REQUEST_IMAGE_GET = 1; public void selectImage() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("prototype/*"); if (intent.resolveActivity(getPackageManager()) != zero) { startActivityForResult(intent, REQUEST_IMAGE_GET); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent information) { if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) { Bitmap thumbnail = data.getParcelable("data"); Uri fullPhotoUri = data.getData(); // Do work with photograph saved at fullPhotoUri ... } } Example intent filter to render a photo:
<activity ...> <intent-filter> <activeness 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 supportsOpenableColumnsandContentResolver.openFileDescriptor()--> <category android:proper noun="android.intent.category.OPENABLE" /> </intent-filter> </activity>
Open a specific type of file
Instead of retrieving a re-create of a file that you lot must import to your app (by using the ACTION_GET_CONTENT action), when running on Android 4.4 or higher, you can instead request to open a file that'due south managed by another app by using the ACTION_OPEN_DOCUMENT action and specifying a MIME blazon. To also allow the user to instead create a new document that your app tin can write to, utilize the ACTION_CREATE_DOCUMENT action instead. For example, instead of selecting from existing PDF documents, the ACTION_CREATE_DOCUMENT intent allows users to select where they'd like to create a new document (inside another app that manages the document's storage)—your app then receives the URI location of where it tin can write the new document.
Whereas the intent delivered to your onActivityResult() method from the ACTION_GET_CONTENT activeness may return a URI of any type, the issue intent from ACTION_OPEN_DOCUMENT and ACTION_CREATE_DOCUMENT always specify the chosen file as a content: URI that's backed by a DocumentsProvider. You tin open up the file with openFileDescriptor() and query its details using columns from DocumentsContract.Certificate.
The returned URI grants your app long-term read access to the file (likewise possibly with write access). Then the ACTION_OPEN_DOCUMENT action is particularly useful (instead of using ACTION_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 let the user to select multiple files by calculation EXTRA_ALLOW_MULTIPLE to the intent, gear up to true. If the user selects only one detail, and so yous can recall the item from getData(). If the user selects more than i item, then getData() returns zilch and you must instead retrieve each detail from a ClipData object that is returned by getClipData().
Note: Your intent must specify a MIME type and must declare the CATEGORY_OPENABLE category. If advisable, you tin specify more than one MIME type by adding an array of MIME types with the EXTRA_MIME_TYPES actress—if y'all exercise and so, you lot must set the principal MIME blazon in setType() to "*/*".
- Activeness
-
ACTION_OPEN_DOCUMENTor
ACTION_CREATE_DOCUMENT - Data URI Scheme
- None
- MIME Type
- The MIME type respective 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 lot utilize this actress, you must set the chief MIME type in
setType()to"*/*". -
EXTRA_ALLOW_MULTIPLE - A boolean that declares whether the user can select more 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 render merely "openable" files that can exist represented as a file stream with
openFileDescriptor().
-
Case intent to get a photo:
Kotlin
const val REQUEST_IMAGE_OPEN = 1 fun selectImage2() { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).utilize { type = "image/*" addCategory(Intent.CATEGORY_OPENABLE) } // Simply the system receives the ACTION_OPEN_DOCUMENT, so no need to exam. startActivityForResult(intent, REQUEST_IMAGE_OPEN) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { if (requestCode == REQUEST_IMAGE_OPEN && resultCode == Action.RESULT_OK) { val fullPhotoUri: Uri = information.data // Practise work with full size photo saved at fullPhotoUri ... } } Java
static final int REQUEST_IMAGE_OPEN = 1; public void selectImage() { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.setType("paradigm/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); // Simply the arrangement receives the ACTION_OPEN_DOCUMENT, and so no need to test. startActivityForResult(intent, REQUEST_IMAGE_OPEN); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_IMAGE_OPEN && resultCode == RESULT_OK) { Uri fullPhotoUri = data.getData(); // Do work with total size photo saved at fullPhotoUri ... } } Third party apps cannot actually reply to an intent with the ACTION_OPEN_DOCUMENT activeness. Instead, the arrangement receives this intent and displays all the files available from various apps in a unified user interface.
To provide your app'southward files in this UI and permit other apps to open them, you must implement a DocumentsProvider and include an intent filter for PROVIDER_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.activeness.DOCUMENTS_PROVIDER" /> </intent-filter> </provider>
For more information near how to brand the files managed past your app openable from other apps, read the Storage Access Framework guide.
Local Actions
Telephone call a car
Google Vocalisation Actions
- "get me a taxi"
- "call me a auto"
(Habiliment OS just)
To phone call a taxi, use the ACTION_RESERVE_TAXI_RESERVATION activeness.
Note: Apps must ask for confirmation from the user before completing the action.
- Action
-
ACTION_RESERVE_TAXI_RESERVATION - Data URI
- None
- MIME Type
- None
- Extras
- None
Instance intent:
Kotlin
fun callCar() { val intent = Intent(ReserveIntents.ACTION_RESERVE_TAXI_RESERVATION) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Coffee
public void callCar() { Intent intent = new Intent(ReserveIntents.ACTION_RESERVE_TAXI_RESERVATION); if (intent.resolveActivity(getPackageManager()) != zero) { startActivity(intent); } } Example intent filter:
<activity ...> <intent-filter> <action android:name="com.google.android.gms.deportment.RESERVE_TAXI_RESERVATION" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activeness>
Maps
Show a location on a map
To open up a map, utilise the ACTION_VIEW action and specify the location information in the intent data with one of the schemes divers below.
- Action
-
ACTION_VIEW - Data URI Scheme
-
-
geo:latitude,longitude - Prove the map at the given longitude and latitude.
Example:
"geo:47.half dozen,-122.3" -
geo:latitude,longitude?z=zoom - Prove 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=xi" -
geo:0,0?q=lat,lng(label) - Prove 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 - Testify the location for "my street accost" (may be a specific address or location query).
Example:
"geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA"Note: All strings passed in the
geoURI must be encoded. For example, the string1st & Pike, Seattleshould get1st%twenty%26%20Pike%2C%20Seattle. Spaces in the cord can be encoded with%xxor replaced with the plus sign (+).
-
- MIME Type
- None
Example intent:
Kotlin
fun showMap(geoLocation: Uri) { val intent = Intent(Intent.ACTION_VIEW).apply { data = geoLocation } if (intent.resolveActivity(packageManager) != goose egg) { startActivity(intent) } } Coffee
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.activeness.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, apply the ACTION_VIEW action and specify the URI location of the file in the intent data.
- Activity
-
ACTION_VIEW - Information URI Scheme
-
-
file:<URI> -
content:<URI> -
http:<URL>
-
- MIME Type
-
-
"audio/*" -
"application/ogg" -
"awarding/x-ogg" -
"application/itunes" - Or any other that your app may require.
-
Case intent:
Kotlin
fun playMedia(file: Uri) { val intent = Intent(Intent.ACTION_VIEW).apply { data = file } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void playMedia(Uri file) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(file); if (intent.resolveActivity(getPackageManager()) != aught) { startActivity(intent); } } Case intent filter:
<activity ...> <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:type="audio/*" /> <data android:blazon="application/ogg" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Play music based on a search query
Google Vocalisation Actions
- "play michael jackson billie jean"
To play music based on a search query, use the INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH intent. An app may burn down this intent in response to the user's voice command to play music. The receiving app for this intent performs a search inside its inventory to match existing content to the given query and starts playing that content.
This intent should include the EXTRA_MEDIA_FOCUS string actress, which specifies the intended search mode. For example, the search way tin specify whether the search is for an artist name or song name.
- Action
-
INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH - Data URI Scheme
- None
- MIME Blazon
- None
- Extras
-
-
MediaStore.EXTRA_MEDIA_FOCUS(required) -
Indicates the search mode (whether the user is looking for a particular artist, album, song, or playlist). Virtually search modes take additional extras. For instance, if the user is interested in listening to a particular song, the intent might have three additional extras: the song title, the creative person, and the album. This intent supports the following search modes for each value of
EXTRA_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 cord. This extra is ever provided for backward compatibility: existing apps that exercise not know almost search modes can process this intent every bit an unstructured search.
-
-
Unstructured -
"vnd.android.cursor.particular/*" -
Play a particular vocal, album or genre from an unstructured search query. Apps may generate an intent with this search style when they can't identify the blazon of content the user wants to heed to. Apps should use more specific search modes when possible.
Boosted extras:
-
QUERY(required) - A string that contains whatever combination of: the artist, the album, the song proper name, or the genre.
-
-
Genre -
Audio.Genres.ENTRY_CONTENT_TYPE -
Play music of a detail 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 near search modes can process this intent as an unstructured search.
-
-
Artist -
Audio.Artists.ENTRY_CONTENT_TYPE -
Play music from a particular creative person.
Additional extras:
-
EXTRA_MEDIA_ARTIST(required) - The artist. -
"android.intent.extra.genre"- The genre. -
QUERY(required) - A cord that contains whatever combination of the artist or the genre. This actress is always provided for astern compatibility: existing apps that do not know about search modes tin can process this intent as an unstructured search.
-
-
Album -
Sound.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 anthology or the creative person. This extra is always provided for backward compatibility: existing apps that do not know almost search modes can process this intent as an unstructured search.
-
-
Song -
"vnd.android.cursor.item/sound" -
Play a detail song.
Boosted extras:
-
EXTRA_MEDIA_ALBUM- The album. -
EXTRA_MEDIA_ARTIST- The artist. -
"android.intent.extra.genre"- The genre. -
EXTRA_MEDIA_TITLE(required) - The song proper name. -
QUERY(required) - A cord that contains whatever combination of: the album, the artist, the genre, or the title. This extra is e'er provided for astern compatibility: existing apps that do non know almost search modes can process this intent every bit an unstructured search.
-
-
Playlist -
Audio.Playlists.ENTRY_CONTENT_TYPE -
Play a detail playlist or a playlist that matches some criteria specified by additional extras.
Additional extras:
-
EXTRA_MEDIA_ALBUM- The anthology. -
EXTRA_MEDIA_ARTIST- The creative person. -
"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 cord that contains any combination of: the album, the artist, the genre, the playlist, or the championship. This extra is ever provided for backward compatibility: existing apps that exercise not know almost search modes tin can process this intent equally an unstructured search.
-
-
-
Example intent:
If the user wants to listen to music from a particular creative person, a search app may generate the following intent:
Kotlin
fun playSearchArtist(artist: String) { val intent = Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH).apply { putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE) putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist) putExtra(SearchManager.QUERY, artist) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
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()) != zip) { startActivity(intent); } } Example intent filter:
<action ...> <intent-filter> <activeness android:name="android.media.activity.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 the EXTRA_MEDIA_FOCUS extra in the incoming Intent to determine the search mode. Once your activity has identified the search manner, it should read the values of the boosted extras for that particular search mode. With this information your app can then perform the search inside its inventory to play the content that matches the search query. For example:
Kotlin
override fun onCreate(savedInstanceState: Bundle?) { ... if (intent.activeness.compareTo(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH) == 0) { val mediaFocus: String? = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS) val query: Cord? = intent.getStringExtra(SearchManager.QUERY) // Some of these extras may non be available depending on the search mode val album: Cord? = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM) val creative person: String? = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST) val genre: String? = intent.getStringExtra("android.intent.extra.genre") val playlist: String? = intent.getStringExtra("android.intent.extra.playlist") val title: String? = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE) // Determine the search style and use the corresponding extras when { mediaFocus == naught -> { // 'Unstructured' search mode (astern compatible) playUnstructuredSearch(query) } mediaFocus.compareTo("vnd.android.cursor.item/*") == 0 -> { if (query?.isNotEmpty() == true) { // 'Unstructured' search fashion playUnstructuredSearch(query) } else { // 'Any' search mode playResumeLastPlaylist() } } mediaFocus.compareTo(MediaStore.Audio.Genres.ENTRY_CONTENT_TYPE) == 0 -> { // 'Genre' search manner playGenre(genre) } mediaFocus.compareTo(MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE) == 0 -> { // 'Creative person' search manner playArtist(artist, genre) } mediaFocus.compareTo(MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE) == 0 -> { // 'Album' search manner playAlbum(album, artist) } mediaFocus.compareTo("vnd.android.cursor.item/audio") == 0 -> { // 'Vocal' search mode playSong(anthology, creative person, genre, title) } mediaFocus.compareTo(MediaStore.Sound.Playlists.ENTRY_CONTENT_TYPE) == 0 -> { // 'Playlist' search mode playPlaylist(album, artist, genre, playlist, title) } } } } Java
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 non be available depending on the search fashion Cord anthology = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM); String creative person = 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); // Make up one's mind the search style and use the respective extras if (mediaFocus == null) { // 'Unstructured' search mode (astern compatible) playUnstructuredSearch(query); } else if (mediaFocus.compareTo("vnd.android.cursor.item/*") == 0) { if (query.isEmpty()) { // 'Whatever' search style playResumeLastPlaylist(); } else { // 'Unstructured' search way 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) { // 'Creative person' search mode playArtist(artist, genre); } else if (mediaFocus.compareTo(MediaStore.Sound.Albums.ENTRY_CONTENT_TYPE) == 0) { // 'Anthology' search fashion playAlbum(anthology, artist); } else if (mediaFocus.compareTo("vnd.android.cursor.item/sound") == 0) { // 'Song' search fashion playSong(album, artist, genre, title); } else if (mediaFocus.compareTo(MediaStore.Sound.Playlists.ENTRY_CONTENT_TYPE) == 0) { // 'Playlist' search mode playPlaylist(album, artist, genre, playlist, title); } } } New Note
Create a annotation
To create a new note, employ the ACTION_CREATE_NOTE action 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 activeness.
- Activeness
-
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 cord indicating the text of the notation.
-
- "telephone call 555-5555"
- "call bob"
- "call voicemail"
- Action
-
-
ACTION_DIAL- Opens the dialer or phone app. -
ACTION_CALL- Places a phone phone call (requires theCALL_PHONEpermission)
-
- Information URI Scheme
-
-
tel:<phone-number> -
voicemail:<phone-number>
-
- MIME Type
- None
-
tel:2125551212 -
tel:(212) 555 1212 - "search for cat videos on myvideoapp"
- Action
-
-
"com.google.android.gms.actions.SEARCH_ACTION" - Support search queries from Google Vocalization Deportment.
-
- Extras
-
-
QUERY - A cord that contains the search query.
-
- Action
-
ACTION_WEB_SEARCH - Information URI Scheme
- None
- MIME Type
- None
- Extras
-
-
SearchManager.QUERY - The search string.
-
- 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_SETTINGSRun across the
Settingsdocumentation for additional settings screens that are bachelor. - Data URI Scheme
- None
- MIME Type
- None
- Activeness
-
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 Blazon
-
-
"text/apparently" -
"paradigm/*" -
"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 theACTION_SEND_MULTIPLEaction, this extra should be anArrayListofUrisouth pointing to the images/videos to attach.
-
- "open case.com"
- Action
-
ACTION_VIEW - Information URI Scheme
-
http:<URL>
https:<URL> - MIME Blazon
-
-
"text/patently" -
"text/html" -
"application/xhtml+xml" -
"application/vnd.wap.xhtml+xml"
-
- Set an Android device for development, or use a virtual device.
- Install a version of your app that handles the intents y'all want to back up.
- Fire an intent using
adb:adb shell am first -a <Activeness> -t <MIME_TYPE> -d <DATA> \ -e <EXTRA_NAME> <EXTRA_VALUE> -due north <Action>
For case:
adb trounce am start -a android.intent.activeness.DIAL \ -d tel:555-5555 -northward org.example.MyApp/.MyActivity
- If you defined the required intent filters, your app should handle the intent.
Example intent:
Kotlin
fun createNote(field of study: Cord, text: Cord) { val intent = Intent(NoteIntents.ACTION_CREATE_NOTE).apply { putExtra(NoteIntents.EXTRA_NAME, subject) putExtra(NoteIntents.EXTRA_TEXT, text) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void createNote(Cord subject, String text) { Intent intent = new Intent(NoteIntents.ACTION_CREATE_NOTE) .putExtra(NoteIntents.EXTRA_NAME, subject field) .putExtra(NoteIntents.EXTRA_TEXT, text); if (intent.resolveActivity(getPackageManager()) != zero) { startActivity(intent); } } Example intent filter:
<action ...> <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 up the phone app and dial a phone number, utilise the ACTION_DIAL action and specify a phone number using the URI scheme defined below. When the telephone app opens, information technology displays the phone number but the user must press the Phone call button to brainstorm the phone phone call.
Google Voice Actions
To place a phone call direct, use the ACTION_CALL action 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 the Call button.
The ACTION_CALL activeness requires that y'all add the CALL_PHONE permission to your manifest file:
<uses-permission android:name="android.permission.CALL_PHONE" />
Valid telephone numbers are those defined in the IETF RFC 3966. Valid examples include the following:
The Phone's dialer is proficient at normalizing schemes, such every bit phone numbers. So the scheme described isn't strictly required in the Uri.parse() method. However, if you have non tried a scheme or are unsure whether information technology can exist handled, utilize the Uri.fromParts() method instead.
Example intent:
Kotlin
fun dialPhoneNumber(phoneNumber: Cord) { val intent = Intent(Intent.ACTION_DIAL).apply { information = Uri.parse("tel:$phoneNumber") } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void dialPhoneNumber(String phoneNumber) { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + phoneNumber)); if (intent.resolveActivity(getPackageManager()) != aught) { startActivity(intent); } } Search
Search using a specific app
Google Vocalisation Actions
To support search inside the context of your app, declare an intent filter in your app with the SEARCH_ACTION action, every bit shown in the example intent filter below.
Note: We no longer recommend using SEARCH_ACTION for app search. Instead, you should implement the GET_THING action to leverage Google Assistant's native support for in-app search. For more information, run across the Google Banana App Actions documentation.
Case intent filter:
<activity android:name=".SearchActivity"> <intent-filter> <activeness android:proper noun="com.google.android.gms.actions.SEARCH_ACTION"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </action>
Perform a web search
To initiate a web search, employ the ACTION_WEB_SEARCH activeness and specify the search string in the SearchManager.QUERY extra.
Example intent:
Kotlin
fun searchWeb(query: Cord) { val intent = Intent(Intent.ACTION_WEB_SEARCH).use { putExtra(SearchManager.QUERY, query) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void searchWeb(String query) { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, query); if (intent.resolveActivity(getPackageManager()) != nix) { startActivity(intent); } } Settings
Open a specific section of Settings
To open a screen in the arrangement settings when your app requires the user to change something, use ane of the following intent actions to open the settings screen corresponding to the action name.
Example intent:
Kotlin
fun openWifiSettings() { val intent = Intent(Settings.ACTION_WIFI_SETTINGS) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Coffee
public void openWifiSettings() { Intent intent = new Intent(Settings.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 bulletin, employ 1 of the intent actions beneath and specify message details such as the phone number, subject, and message body using the extra keys listed below.
Example intent:
Kotlin
fun composeMmsMessage(message: String, zipper: Uri) { val intent = Intent(Intent.ACTION_SENDTO).employ { type = HTTP.PLAIN_TEXT_TYPE putExtra("sms_body", message) putExtra(Intent.EXTRA_STREAM, attachment) } if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Java
public void composeMmsMessage(String bulletin, 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()) != zippo) { startActivity(intent); } } If you lot want to ensure that your intent is handled simply by a text messaging app (and non other email or social apps), and then use the ACTION_SENDTO activeness and include the "smsto:" data scheme. For example:
Kotlin
fun composeMmsMessage(message: String, attachment: Uri) { val intent = Intent(Intent.ACTION_SEND).utilize { information = Uri.parse("smsto:") // This ensures only SMS apps respond putExtra("sms_body", message) putExtra(Intent.EXTRA_STREAM, attachment) } if (intent.resolveActivity(packageManager) != nil) { startActivity(intent) } } Coffee
public void composeMmsMessage(Cord message, Uri attachment) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setData(Uri.parse("smsto:")); // This ensures but SMS apps respond intent.putExtra("sms_body", bulletin); intent.putExtra(Intent.EXTRA_STREAM, attachment); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } Example intent filter:
<action ...> <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> </activeness>
Note: If y'all're developing an SMS/MMS messaging app, you must implement intent filters for several additional actions in order to exist available every bit the default SMS app on Android iv.4 and higher. For more than information, see the documentation at Telephony.
Web Browser
Load a web URL
Google Voice Actions
To open up a spider web page, utilise the ACTION_VIEW activeness and specify the web URL in the intent data.
Example intent:
Kotlin
fun openWebPage(url: String) { val webpage: Uri = Uri.parse(url) val intent = Intent(Intent.ACTION_VIEW, webpage) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } } Coffee
public void openWebPage(String url) { Uri webpage = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, webpage); if (intent.resolveActivity(getPackageManager()) != zero) { startActivity(intent); } } Instance intent filter:
<activity ...> <intent-filter> <activity android:name="android.intent.action.VIEW" /> <!-- Include the host attribute if you want your app to answer only to URLs with your app'southward domain. --> <data android:scheme="http" android:host="www.example.com" /> <category android:name="android.intent.category.DEFAULT" /> <!-- The BROWSABLE category is required to become 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 spider web site open your Android app instead of your spider web page. Learn more in the guides about Handling Android App Links.
Starting in Android 12 (API level 31), a generic web intent resolves to an activeness in your app only if your app is canonical for the specific domain independent in that web intent. If your app isn't canonical for the domain, the web intent resolves to the user'southward default browser app instead.
Verify Intents with the Android Debug Span
To verify that your app responds to the intents that you want to support, you tin can utilise the adb tool to fire specific intents:
For more data, see ADB Shell Commands.
Source: https://developer.android.com/guide/components/intents-common
0 Response to "Legalsounds Streams Email Resources Apps Arts Messaging Communities Wireles"
Postar um comentário