diff --git a/docs/html/guide/components/images/google-action.png b/docs/html/guide/components/images/google-action.png new file mode 100644 index 0000000000000..f716d3d19f59b Binary files /dev/null and b/docs/html/guide/components/images/google-action.png differ diff --git a/docs/html/guide/components/images/google-action_2x.png b/docs/html/guide/components/images/google-action_2x.png new file mode 100644 index 0000000000000..81a349d698555 Binary files /dev/null and b/docs/html/guide/components/images/google-action_2x.png differ diff --git a/docs/html/guide/components/images/voice-icon.png b/docs/html/guide/components/images/voice-icon.png new file mode 100644 index 0000000000000..b2e9e85c2a000 Binary files /dev/null and b/docs/html/guide/components/images/voice-icon.png differ diff --git a/docs/html/guide/components/intents-common.jd b/docs/html/guide/components/intents-common.jd index af9456de47f7e..5954645430222 100644 --- a/docs/html/guide/components/intents-common.jd +++ b/docs/html/guide/components/intents-common.jd @@ -26,6 +26,8 @@ page.tags="IntentFilter"
  • Camera
    1. Capture a picture or video and return it
    2. +
    3. Start a camera app in still image mode
    4. +
    5. Start a camera app in video mode
  • Contacts/People App @@ -48,6 +50,20 @@ page.tags="IntentFilter"
  • Open a specific type of file
  • +
  • Fitness +
      +
    1. Start/Stop a bike ride
    2. +
    3. Start/Stop a run
    4. +
    5. Start/Stop a workout
    6. +
    7. Show heart rate
    8. +
    9. Show step count
    10. +
    +
  • +
  • Local Actions +
      +
    1. Call a car
    2. +
    +
  • Maps
    1. Show a location on a map
    2. @@ -80,6 +96,8 @@ page.tags="IntentFilter"
    3. Perform a web search
  • +
  • Verify Intents with the Android Debug Bridge
  • +
  • Intents Fired by Google Now
  • See also

    @@ -90,6 +108,46 @@ Filters + +

    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") @@ -121,12 +179,17 @@ it's safe to call {@link android.content.Context#startActivity startActivity()}. 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 read Intents and Intent Filters.

    +

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

    +

    Google Now

    +

    Google Now fires some of the intents listed +on this page in response to voice commands. For more information, see +Intents Fired by Google Now.

    @@ -138,11 +201,25 @@ the intent.

    Create an alarm

    + +
    +
    + + + +
    +

    Google Now

    + +
    +

    To create a new alarm, use the {@link android.provider.AlarmClock#ACTION_SET_ALARM} action and specify alarm details such as the time and message using extras defined below.

    Note: Only the hour, minutes, and message extras are available -since Android 2.3 (API level 9). The other extras were added in later versions of the platform.

    +in Android 2.3 (API level 9) and higher. The other extras were added in later versions of the +platform.

    Action
    @@ -221,6 +298,19 @@ android.provider.AlarmClock#ACTION_SET_ALARM} intent, your app must have the

    Create a timer

    + +
    +
    + + + +
    +

    Google Now

    + +
    +

    To create a countdown timer, use the {@link android.provider.AlarmClock#ACTION_SET_TIMER} action and specify timer details such as the duration using extras defined below.

    @@ -509,6 +599,116 @@ in an extra named "data".

    +

    Start a camera app in still image mode

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To open a camera app in still image mode, use the {@link +android.provider.MediaStore#INTENT_ACTION_STILL_IMAGE_CAMERA} action.

    + +
    +
    Action
    +
    {@link android.provider.MediaStore#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

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To open a camera app in video mode, use the {@link +android.provider.MediaStore#INTENT_ACTION_VIDEO_CAMERA} action.

    + +
    +
    Action
    +
    {@link android.provider.MediaStore#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

    @@ -668,10 +868,10 @@ action and specify the contact with a {@code content:} URI as the intent data.There are primarily two ways to initially retrieve the contact's URI:

    @@ -709,10 +909,10 @@ constants in {@link android.provider.ContactsContract.Intents.Insert}.

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

    @@ -802,7 +1002,6 @@ Contacts Using Intents.

    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.

    @@ -901,6 +1100,73 @@ public void composeEmail(String[] addresses, String subject) { +

    Notes

    + + +

    Take a note

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To take a note, use the {@link android.content.Intent#ACTION_SEND} action and specify the +text for the note with the {@link android.content.Intent#EXTRA_TEXT}.

    + +
    +
    Action
    +
    {@link android.content.Intent#ACTION_SEND}
    + +
    Category
    +
    com.google.android.voicesearch.SELF_NOTE
    + +
    Data URI Scheme
    +
    None
    + +
    Extras
    +
    +
    +
    {@link android.content.Intent#EXTRA_TEXT}
    +
    A string with the contents of the note.
    +
    +
    + +
    + + +

    Example intent:

    +
    +public void takeNote(String content) {
    +    Intent intent = new Intent(Intent.ACTION_SEND);
    +    intent.setType("*/*");
    +    intent.putExtra(Intent.EXTRA_TEXT, content);
    +    if (intent.resolveActivity(getPackageManager()) != null) {
    +        startActivity(intent);
    +    }
    +}
    +
    + + +

    Example intent filter:

    +
    +<activity ...>
    +    <intent-filter>
    +        <action android:name="android.intent.action.SEND" />
    +        <category android:name="com.google.android.voicesearch.SELF_NOTE" />
    +    </intent-filter>
    +</activity>
    +
    + + @@ -1153,6 +1419,410 @@ Framework guide.

    +

    Fitness

    + +

    Start/Stop a bike ride

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To track a bike ride, use the "vnd.google.fitness.TRACK" action with the +"vnd.google.fitness.activity/biking" MIME type and set the "actionStatus" +extra to "ActiveActionStatus" when starting and to "CompletedActionStatus" +when stopping.

    + +
    +
    Action
    +
    "vnd.google.fitness.TRACK"
    + +
    Data URI
    +
    None
    + +
    MIME Type
    +
    "vnd.google.fitness.activity/biking"
    + +
    Extras
    +
    +
    +
    "actionStatus"
    +
    A string with the value "ActiveActionStatus" when starting and + "CompletedActionStatus" when stopping.
    +
    +
    +
    + + +

    Example intent:

    +
    +public void startBikeRide() {
    +    Intent intent = new Intent("vnd.google.fitness.TRACK")
    +            .setType("vnd.google.fitness.activity/biking")
    +            .putExtra("actionStatus", "ActiveActionStatus");
    +    if (intent.resolveActivity(getPackageManager()) != null) {
    +        startActivity(intent);
    +    }
    +}
    +
    + + +

    Example intent filter:

    +
    +<activity ...>
    +    <intent-filter>
    +        <action android:name="vnd.google.fitness.TRACK" />
    +        <data android:mimeType="vnd.google.fitness.activity/biking" />
    +        <category android:name="android.intent.category.DEFAULT" />
    +    </intent-filter>
    +</activity>
    +
    + + + + + +

    Start/Stop a run

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To track a run, use the "vnd.google.fitness.TRACK" action with the +"vnd.google.fitness.activity/running" MIME type and set the "actionStatus" +extra to "ActiveActionStatus" when starting and to "CompletedActionStatus" +when stopping.

    + +
    +
    Action
    +
    "vnd.google.fitness.TRACK"
    + +
    Data URI
    +
    None
    + +
    MIME Type
    +
    "vnd.google.fitness.activity/running"
    + +
    Extras
    +
    +
    +
    "actionStatus"
    +
    A string with the value "ActiveActionStatus" when starting and + "CompletedActionStatus" when stopping.
    +
    +
    +
    + + +

    Example intent:

    +
    +public void startRun() {
    +    Intent intent = new Intent("vnd.google.fitness.TRACK")
    +            .setType("vnd.google.fitness.activity/running")
    +            .putExtra("actionStatus", "ActiveActionStatus");
    +    if (intent.resolveActivity(getPackageManager()) != null) {
    +        startActivity(intent);
    +    }
    +}
    +
    + + +

    Example intent filter:

    +
    +<activity ...>
    +    <intent-filter>
    +        <action android:name="vnd.google.fitness.TRACK" />
    +        <data android:mimeType="vnd.google.fitness.activity/running" />
    +        <category android:name="android.intent.category.DEFAULT" />
    +    </intent-filter>
    +</activity>
    +
    + + + + +

    Start/Stop a workout

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To track a workout, use the "vnd.google.fitness.TRACK" action with the +"vnd.google.fitness.activity/other" MIME type and set the "actionStatus" +extra to "ActiveActionStatus" when starting and to "CompletedActionStatus" +when stopping.

    + +
    +
    Action
    +
    "vnd.google.fitness.TRACK"
    + +
    Data URI
    +
    None
    + +
    MIME Type
    +
    "vnd.google.fitness.activity/other"
    + +
    Extras
    +
    +
    +
    "actionStatus"
    +
    A string with the value "ActiveActionStatus" when starting and + "CompletedActionStatus" when stopping.
    +
    +
    +
    + + +

    Example intent:

    +
    +public void startWorkout() {
    +    Intent intent = new Intent("vnd.google.fitness.TRACK")
    +            .setType("vnd.google.fitness.activity/other")
    +            .putExtra("actionStatus", "ActiveActionStatus");
    +    if (intent.resolveActivity(getPackageManager()) != null) {
    +        startActivity(intent);
    +    }
    +}
    +
    + + +

    Example intent filter:

    +
    +<activity ...>
    +    <intent-filter>
    +        <action android:name="vnd.google.fitness.TRACK" />
    +        <data android:mimeType="vnd.google.fitness.activity/other" />
    +        <category android:name="android.intent.category.DEFAULT" />
    +    </intent-filter>
    +</activity>
    +
    + + + + +

    Show heart rate

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To show the user's heart rate, use the "vnd.google.fitness.VIEW" action with the +"vnd.google.fitness.data_type
    /com.google.heart_rate.bpm"
    MIME type.

    + +
    +
    Action
    +
    "vnd.google.fitness.VIEW"
    + +
    Data URI
    +
    None
    + +
    MIME Type
    +
    "vnd.google.fitness.data_type/com.google.heart_rate.bpm"
    + +
    Extras
    +
    None
    +
    + + +

    Example intent:

    +
    +public void showHR() {
    +    Intent intent = new Intent("vnd.google.fitness.VIEW")
    +            .setType("vnd.google.fitness.data_type/com.google.heart_rate.bpm");
    +    if (intent.resolveActivity(getPackageManager()) != null) {
    +        startActivity(intent);
    +    }
    +}
    +
    + + +

    Example intent filter:

    +
    +<activity ...>
    +    <intent-filter>
    +        <action android:name="vnd.google.fitness.VIEW" />
    +        <data android:mimeType="vnd.google.fitness.data_type/com.google.heart_rate.bpm" />
    +        <category android:name="android.intent.category.DEFAULT" />
    +    </intent-filter>
    +</activity>
    +
    + + + + + +

    Show step count

    + + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To show the user's step count, use the "vnd.google.fitness.VIEW" action with the +"vnd.google.fitness.data_type
    /com.google.step_count.cumulative"
    MIME type.

    + +
    +
    Action
    +
    "vnd.google.fitness.VIEW"
    + +
    Data URI
    +
    None
    + +
    MIME Type
    +
    "vnd.google.fitness.data_type/com.google.step_count.cumulative"
    + +
    Extras
    +
    None
    +
    + + +

    Example intent:

    +
    +public void showStepCount() {
    +    Intent intent = new Intent("vnd.google.fitness.VIEW")
    +            .setType("vnd.google.fitness.data_type/com.google.step_count.cumulative");
    +    if (intent.resolveActivity(getPackageManager()) != null) {
    +        startActivity(intent);
    +    }
    +}
    +
    + + +

    Example intent filter:

    +
    +<activity ...>
    +    <intent-filter>
    +        <action android:name="vnd.google.fitness.VIEW" />
    +        <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.cumulative" />
    +        <category android:name="android.intent.category.DEFAULT" />
    +    </intent-filter>
    +</activity>
    +
    + + + + + + + + +

    Local Actions

    + +

    Call a car

    + + +
    +
    + + + +
    +

    Google Now

    + +

    (Android Wear only)

    +
    + +

    To call a taxi, use the +ACTION_RESERVE_TAXI_RESERVATION +action.

    + +

    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
    +
    + + +

    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>
    +
    + + + + + @@ -1290,6 +1960,19 @@ public void playMedia(Uri file) {

    Play music based on a search query

    + +
    +
    + + + +
    +

    Google Now

    + +
    +

    To play music based on a search query, use the {@link android.provider.MediaStore#INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH} intent. An app may fire this intent in response to the user's voice command to play music. The receiving app for this @@ -1523,13 +2206,49 @@ android.content.Intent#ACTION_DIAL} action 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 the Call button to begin the phone call.

    + +
    +
    + + + +
    +

    Google Now

    + +
    + +

    To place a phone call directly, use the {@link android.content.Intent#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 {@link android.content.Intent#ACTION_CALL} action requires that you add the +CALL_PHONE permission to your manifest file:

    + +
    +<uses-permission android:name="android.permission.CALL_PHONE" />
    +
    Action
    -
    {@link android.content.Intent#ACTION_DIAL}
    +
    +
      +
    • {@link android.content.Intent#ACTION_DIAL} - Opens the dialer or phone app.
    • +
    • {@link android.content.Intent#ACTION_CALL} - Places a phone call (requires the + CALL_PHONE permission)
    • +
    +
    Data URI Scheme
    -
    {@code tel:<phone-number>}
    +
    +
      +
    • {@code tel:<phone-number>}
    • +
    • {@code voicemail:<phone-number>}
    • +
    +
    MIME Type
    None
    @@ -1569,9 +2288,6 @@ public void dialPhoneNumber(String phoneNumber) { - - -

    Settings

    Open a specific section of Settings

    @@ -1735,6 +2451,19 @@ at {@link android.provider.Telephony}.

    Load a web URL

    + +
    +
    + + + +
    +

    Google Now

    +
      +
    • "open example.com"
    • +
    +
    +

    To open a web page, use the {@link android.content.Intent#ACTION_VIEW} action and specify the web URL in the intent data.

    @@ -1833,3 +2562,210 @@ public void searchWeb(String query) { + + + + +

    Verify Intents with the Android Debug Bridge

    + +

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

    + +
      +
    1. Set up an Android device for development, +or use a virtual device.
    2. +
    3. Install a version of your app that handles the intents you want to support.
    4. +
    5. Fire an intent using adb: +
      +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
      +
      +
    6. If you defined the required intent filters, your app should handle the intent.
    7. +
    + + +

    For more information, see +Using activity manager (am).

    + + + + + + +

    Intents Fired by Google Now

    + +

    Google Now recognizes 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 can +set an alarm and 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).

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CategoryDetails and ExamplesAction Name
    Alarm +

    Set alarm

    +
      +
    • "set an alarm for 7 am"
    • +
    +
    {@link android.provider.AlarmClock#ACTION_SET_ALARM AlarmClock.ACTION_SET_ALARM}
    +

    Set timer

    +
      +
    • "set a timer for 5 minutes"
    • +
    +
    {@link android.provider.AlarmClock#ACTION_SET_TIMER AlarmClock.ACTION_SET_TIMER}
    Communication +

    Call a number

    +
      +
    • "call 555-5555"
    • +
    • "call bob"
    • +
    • "call voicemail"
    • +
    +
    {@link android.content.Intent#ACTION_CALL Intent.ACTION_CALL}
    +

    Note to self

    +
      +
    • "take a note"
    • +
    • "note to self"
    • +
    +
    {@link android.content.Intent#ACTION_SEND Intent.ACTION_SEND}
    Fitness +

    Start/stop a bike ride

    +
      +
    • "start cycling"
    • +
    • "start my bike ride"
    • +
    • "stop cycling"
    • +
    +
    "vnd.google.fitness.TRACK"
    +

    Start/stop a run

    +
      +
    • "track my run"
    • +
    • "start running"
    • +
    • "stop running"
    • +
    +
    "vnd.google.fitness.TRACK"
    +

    Start/stop a workout

    +
      +
    • "start a workout"
    • +
    • "track my workout"
    • +
    • "stop workout"
    • +
    +
    "vnd.google.fitness.TRACK"
    +

    Show heart rate

    +
      +
    • "what's my heart rate"
    • +
    • "what's my bpm"
    • +
    +
    "vnd.google.fitness.VIEW"
    +

    Show step count

    +
      +
    • "how many steps have I taken"
    • +
    • "what's my step count"
    • +
    +
    "vnd.google.fitness.VIEW"
    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"
    • +
    +
    {@link android.provider.MediaStore#INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH MediaStore
    .INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH}
    +

    Take a picture

    +
      +
    • "take a picture"
    • +
    +
    {@link android.provider.MediaStore#INTENT_ACTION_STILL_IMAGE_CAMERA MediaStore
    .INTENT_ACTION_STILL_IMAGE_CAMERA}
    +

    Record a video

    +
      +
    • "record a video"
    • +
    +
    {@link android.provider.MediaStore#INTENT_ACTION_VIDEO_CAMERA MediaStore
    .INTENT_ACTION_VIDEO_CAMERA}
    Web browser +

    Open URL

    +
      +
    • "open example.com"
    • +
    +
    {@link android.content.Intent#ACTION_VIEW Intent.ACTION_VIEW}