1 page.title=Common Intents 2 page.tags="IntentFilter" 3 @jd:body 4 5 <div id="qv-wrapper"> 6 <div id="qv"> 7 8 <h2>In this document 9 <a href="#" onclick="hideNestedItems('#tocIntents',this);return false;" class="header-toggle"> 10 <span class="more">show more</span> 11 <span class="less" style="display:none">show less</span></a></h2> 12 13 <ol id="tocIntents" class="hide-nested"> 14 <li><a href="#Clock">Alarm Clock</a> 15 <ol> 16 <li><a href="#CreateAlarm">Create an alarm</a></li> 17 <li><a href="#CreateTimer">Create a timer</a></li> 18 <li><a href="#ShowAlarms">Show all alarms</a></li> 19 </ol> 20 </li> 21 <li><a href="#Calendar">Calendar</a> 22 <ol> 23 <li><a href="#AddEvent">Add a calendar event</a></li> 24 </ol> 25 </li> 26 <li><a href="#Camera">Camera</a> 27 <ol> 28 <li><a href="#ImageCapture">Capture a picture or video and return it</a></li> 29 <li><a href="#CameraStill">Start a camera app in still image mode</a></li> 30 <li><a href="#CameraVideo">Start a camera app in video mode</a></li> 31 </ol> 32 </li> 33 <li><a href="#Contacts">Contacts/People App</a> 34 <ol> 35 <li><a href="#PickContact">Select a contact</a></li> 36 <li><a href="#PickContactDat">Select specific contact data</a></li> 37 <li><a href="#ViewContact">View a contact</a></li> 38 <li><a href="#EditContact">Edit an existing contact</a></li> 39 <li><a href="#InsertContact">Insert a contact</a></li> 40 </ol> 41 </li> 42 <li><a href="#Email">Email</a> 43 <ol> 44 <li><a href="#ComposeEmail">Compose an email with optional attachments</a></li> 45 </ol> 46 </li> 47 <li><a href="#Storage">File Storage</a> 48 <ol> 49 <li><a href="#GetFile">Retrieve a specific type of file</a></li> 50 <li><a href="#OpenFile">Open a specific type of file</a></li> 51 </ol> 52 </li> 53 <li><a href="#Fitness">Fitness</a> 54 <ol> 55 <li><a href="#TrackRide">Start/Stop a bike ride</a></li> 56 <li><a href="#TrackRun">Start/Stop a run</a></li> 57 <li><a href="#TrackWorkout">Start/Stop a workout</a></li> 58 <li><a href="#ShowHR">Show heart rate</a></li> 59 <li><a href="#ShowStepCount">Show step count</a></li> 60 </ol> 61 </li> 62 <li><a href="#Local">Local Actions</a> 63 <ol> 64 <li><a href="#CallCar">Call a car</a></li> 65 </ol> 66 </li> 67 <li><a href="#Maps">Maps</a> 68 <ol> 69 <li><a href="#ViewMap">Show a location on a map</a></li> 70 </ol> 71 </li> 72 <li><a href="#Music">Music or Video</a> 73 <ol> 74 <li><a href="#PlayMedia">Play a media file</a></li> 75 <li><a href="#PlaySearch">Play music based on a search query</a></li> 76 </ol> 77 </li> 78 <li><a href="#Phone">Phone</a> 79 <ol> 80 <li><a href="#DialPhone">Initiate a phone call</a></li> 81 </ol> 82 </li> 83 </li> 84 <li><a href="#Search">Search</a> 85 <ol> 86 <li><a href="#SearchOnApp">Search in a specific app</a></li> 87 <li><a href="#SearchWeb">Perform a web search</a></li> 88 </ol> 89 </li> 90 <li><a href="#Settings">Settings</a> 91 <ol> 92 <li><a href="#OpenSettings">Open a specific section of Settings</a></li> 93 </ol> 94 </li> 95 <li><a href="#Messaging">Text Messaging</a> 96 <ol> 97 <li><a href="#SendMessage">Compose an SMS/MMS message with attachment</a></li> 98 </ol> 99 </li> 100 <li><a href="#Browser">Web Browser</a> 101 <ol> 102 <li><a href="#ViewUrl">Load a web URL</a></li> 103 </ol> 104 </li> 105 <li><a href="#AdbIntents">Verify Intents with the Android Debug Bridge</a></li> 106 <li><a href="#Now">Intents Fired by Google Now</a></li> 107 </ol> 108 109 <h2>See also</h2> 110 <ol> 111 <li><a href="{@docRoot}guide/components/intents-filters.html">Intents and Intent 112 Filters</a></li> 113 </ol> 114 </div> 115 </div> 116 117 <!-- Google Now box styles --> 118 <style type="text/css"> 119 .now-box { 120 border-color: rgb(204,204,204); 121 border-style: solid; 122 border-width: 1px; 123 float: right; 124 margin: 0px 0px 20px 15px; 125 padding: 17px; 126 width: 200px; 127 } 128 .now-box li { 129 font-size: 13px; 130 font-style: italic; 131 margin-top: 0px; 132 } 133 .now-box ul { 134 margin-bottom: 0px; 135 } 136 .now-img { 137 width: 30px; 138 margin-bottom: 0px !important; 139 } 140 .now-img-cont { 141 float: left; 142 margin-right: 10px; 143 } 144 .now-title { 145 font-weight: bold; 146 margin-top: 7px; 147 } 148 .now-list { 149 font-size: 13px; 150 margin-bottom: 10px !important; 151 list-style-type: none; 152 } 153 .now-list li { 154 font-style: italic; 155 } 156 </style> 157 158 <p>An intent allows you to start an activity in another app by describing a simple 159 action you'd like to perform (such as "view a map" or "take a picture") 160 in an {@link android.content.Intent} object. This type of intent is 161 called an <em>implicit</em> intent because it does not specify the app component 162 to start, but instead specifies an <em>action</em> and provides some 163 <em>data</em> with which to perform the action.</p> 164 165 <p>When you call 166 {@link android.content.Context#startActivity startActivity()} or 167 {@link android.app.Activity#startActivityForResult startActivityForResult()} and pass it an 168 implicit intent, the system <a href="{@docRoot}guide/components/intents-filters.html#Resolution" 169 >resolves the intent</a> to an app that can handle the intent 170 and starts its corresponding {@link android.app.Activity}. If there's more than one app 171 that can handle the intent, the system presents the user with a dialog to pick which app 172 to use.</p> 173 174 <p>This page describes several implicit intents that you can use to perform common actions, 175 organized by the type of app that handles the intent. Each section also shows how you can 176 create an <a href="{@docRoot}guide/components/intents-filters.html#Receiving">intent filter</a> to 177 advertise your app's ability to perform the same action.</p> 178 179 <p class="caution"><strong>Caution:</strong> If there are no apps on the device that can receive 180 the implicit intent, your app will crash when it calls {@link android.content.Context#startActivity 181 startActivity()}. To first verify that an app exists to receive the intent, call {@link 182 android.content.Intent#resolveActivity resolveActivity()} on your {@link android.content.Intent} 183 object. If the result is non-null, there is at least one app that can handle the intent and 184 it's safe to call {@link android.content.Context#startActivity startActivity()}. If the result is 185 null, you should not use the intent and, if possible, you should disable the feature that invokes 186 the intent.</p> 187 188 <p>If you're not familiar with how to create intents or intent filters, you should first read 189 <a href="{@docRoot}guide/components/intents-filters.html">Intents and Intent Filters</a>.</p> 190 191 <p>To learn how to fire the intents listed on this page from your development host, see 192 <a href="#AdbIntents">Verify Intents with the Android Debug Bridge</a>.</p> 193 194 <h4>Google Now</h4> 195 196 <p><a href="http://www.google.com/landing/now/">Google Now</a> fires some of the intents listed 197 on this page in response to voice commands. For more information, see 198 <a href="#Now">Intents Fired by Google Now</a>.</p> 199 200 201 202 203 204 205 <h2 id="Clock">Alarm Clock</h2> 206 207 208 <h3 id="CreateAlarm">Create an alarm</h3> 209 210 <!-- Google Now box --> 211 <div class="now-box"> 212 <div class="now-img-cont"> 213 <a href="#Now"> 214 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" width="30" 215 height="30" alt=""/> 216 </a> 217 </div> 218 <p class="now-title">Google Now</p> 219 <ul> 220 <li>"set an alarm for 7 am"</li> 221 </ul> 222 </div> 223 224 <p>To create a new alarm, use the {@link android.provider.AlarmClock#ACTION_SET_ALARM} 225 action and specify alarm details such as the time and message using extras defined below.</p> 226 227 <p class="note"><strong>Note:</strong> Only the hour, minutes, and message extras are available 228 in Android 2.3 (API level 9) and higher. The other extras were added in later versions of the 229 platform.</p> 230 231 <dl> 232 <dt><b>Action</b></dt> 233 <dd>{@link android.provider.AlarmClock#ACTION_SET_ALARM}</dd> 234 235 <dt><b>Data URI</b></dt> 236 <dd>None</dd> 237 238 <dt><b>MIME Type</b></dt> 239 <dd>None 240 </dd> 241 242 <dt><b>Extras</b></dt> 243 <dd> 244 <dl> 245 <dt>{@link android.provider.AlarmClock#EXTRA_HOUR}</dt> 246 <dd>The hour for the alarm.</dd> 247 <dt>{@link android.provider.AlarmClock#EXTRA_MINUTES}</dt> 248 <dd>The minutes for the alarm.</dd> 249 <dt>{@link android.provider.AlarmClock#EXTRA_MESSAGE}</dt> 250 <dd>A custom message to identify the alarm.</dd> 251 <dt>{@link android.provider.AlarmClock#EXTRA_DAYS}</dt> 252 <dd>An {@link java.util.ArrayList} including each week day on which this alarm should 253 be repeated. Each day must be declared with an integer from the {@link java.util.Calendar} 254 class such as {@link java.util.Calendar#MONDAY}. 255 <p>For a one-time alarm, do not specify this extra.</dd> 256 <dt>{@link android.provider.AlarmClock#EXTRA_RINGTONE}</dt> 257 <dd>A {@code content:} URI specifying a ringtone to use with the alarm, or {@link 258 android.provider.AlarmClock#VALUE_RINGTONE_SILENT} for no ringtone. 259 <p>To use the default ringtone, do not specify this extra.</dd> 260 <dt>{@link android.provider.AlarmClock#EXTRA_VIBRATE}</dt> 261 <dd>A boolean specifying whether to vibrate for this alarm.</dd> 262 <dt>{@link android.provider.AlarmClock#EXTRA_SKIP_UI}</dt> 263 <dd>A boolean specifying whether the responding app should skip its UI when setting the alarm. 264 If true, the app should bypass any confirmation UI and simply set the specified alarm.</dd> 265 </dl> 266 </dd> 267 268 269 </dl> 270 271 <p><b>Example intent:</b></p> 272 <pre> 273 public void createAlarm(String message, int hour, int minutes) { 274 Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM) 275 .putExtra(AlarmClock.EXTRA_MESSAGE, message) 276 .putExtra(AlarmClock.EXTRA_HOUR, hour) 277 .putExtra(AlarmClock.EXTRA_MINUTES, minutes); 278 if (intent.resolveActivity(getPackageManager()) != null) { 279 startActivity(intent); 280 } 281 } 282 </pre> 283 284 <div class="note"><strong>Note:</strong> 285 <p>In order to invoke the {@link 286 android.provider.AlarmClock#ACTION_SET_ALARM} intent, your app must have the 287 {@link android.Manifest.permission#SET_ALARM} permission:</p> 288 <pre> 289 <uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> 290 </pre> 291 </div> 292 293 294 <p><b>Example intent filter:</b></p> 295 <pre> 296 <activity ...> 297 <intent-filter> 298 <action android:name="android.intent.action.SET_ALARM" /> 299 <category android:name="android.intent.category.DEFAULT" /> 300 </intent-filter> 301 </activity> 302 </pre> 303 304 305 306 <h3 id="CreateTimer">Create a timer</h3> 307 308 <!-- Google Now box --> 309 <div class="now-box"> 310 <div class="now-img-cont"> 311 <a href="#Now"> 312 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 313 width="30" height="30" alt=""/> 314 </a> 315 </div> 316 <p class="now-title">Google Now</p> 317 <ul> 318 <li>"set timer for 5 minutes"</li> 319 </ul> 320 </div> 321 322 <p>To create a countdown timer, use the {@link android.provider.AlarmClock#ACTION_SET_TIMER} 323 action and specify timer details such as the duration using extras defined below.</p> 324 325 <p class="note"><strong>Note:</strong> This intent was added 326 in Android 4.4 (API level 19).</p> 327 328 <dl> 329 <dt><b>Action</b></dt> 330 <dd>{@link android.provider.AlarmClock#ACTION_SET_TIMER}</dd> 331 332 <dt><b>Data URI</b></dt> 333 <dd>None</dd> 334 335 <dt><b>MIME Type</b></dt> 336 <dd>None 337 </dd> 338 339 <dt><b>Extras</b></dt> 340 <dd> 341 <dl> 342 <dt>{@link android.provider.AlarmClock#EXTRA_LENGTH}</dt> 343 <dd>The length of the timer in seconds.</dd> 344 <dt>{@link android.provider.AlarmClock#EXTRA_MESSAGE}</dt> 345 <dd>A custom message to identify the timer.</dd> 346 <dt>{@link android.provider.AlarmClock#EXTRA_SKIP_UI}</dt> 347 <dd>A boolean specifying whether the responding app should skip its UI when setting the timer. 348 If true, the app should bypass any confirmation UI and simply start the specified timer.</dd> 349 </dl> 350 </dd> 351 352 353 </dl> 354 355 <p><b>Example intent:</b></p> 356 <pre> 357 public void startTimer(String message, int seconds) { 358 Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER) 359 .putExtra(AlarmClock.EXTRA_MESSAGE, message) 360 .putExtra(AlarmClock.EXTRA_LENGTH, seconds) 361 .putExtra(AlarmClock.EXTRA_SKIP_UI, true); 362 if (intent.resolveActivity(getPackageManager()) != null) { 363 startActivity(intent); 364 } 365 } 366 </pre> 367 368 <div class="note"><strong>Note:</strong> 369 <p>In order to invoke the {@link 370 android.provider.AlarmClock#ACTION_SET_TIMER} intent, your app must have the 371 {@link android.Manifest.permission#SET_ALARM} permission:</p> 372 <pre> 373 <uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> 374 </pre> 375 </div> 376 377 378 <p><b>Example intent filter:</b></p> 379 <pre> 380 <activity ...> 381 <intent-filter> 382 <action android:name="android.intent.action.SET_TIMER" /> 383 <category android:name="android.intent.category.DEFAULT" /> 384 </intent-filter> 385 </activity> 386 </pre> 387 388 389 390 391 392 <h3 id="ShowAlarms">Show all alarms</h3> 393 394 <p>To show the list of alarms, use the {@link android.provider.AlarmClock#ACTION_SHOW_ALARMS} 395 action.</p> 396 397 <p>Although not many apps will invoke this intent (it's primarily used by system apps), 398 any app that behaves as an alarm clock should implement 399 this intent filter and respond by showing the list of current alarms.</p> 400 401 <p class="note"><strong>Note:</strong> This intent was added 402 in Android 4.4 (API level 19).</p> 403 404 <dl> 405 <dt><b>Action</b></dt> 406 <dd>{@link android.provider.AlarmClock#ACTION_SHOW_ALARMS}</dd> 407 408 <dt><b>Data URI</b></dt> 409 <dd>None</dd> 410 411 <dt><b>MIME Type</b></dt> 412 <dd>None 413 </dd> 414 </dl> 415 416 <p><b>Example intent filter:</b></p> 417 <pre> 418 <activity ...> 419 <intent-filter> 420 <action android:name="android.intent.action.SHOW_ALARMS" /> 421 <category android:name="android.intent.category.DEFAULT" /> 422 </intent-filter> 423 </activity> 424 </pre> 425 426 427 428 429 430 431 <h2 id="Calendar">Calendar</h2> 432 433 434 <h3 id="AddEvent">Add a calendar event</h3> 435 436 <p>To add a new event to the user's calendar, use the {@link android.content.Intent#ACTION_INSERT} 437 action and specify the data URI with {@link android.provider.CalendarContract.Events#CONTENT_URI 438 Events.CONTENT_URI}. You can then specify various event details using extras defined below.</p> 439 440 <dl> 441 <dt><b>Action</b></dt> 442 <dd>{@link android.content.Intent#ACTION_INSERT}</dd> 443 444 <dt><b>Data URI</b></dt> 445 <dd>{@link android.provider.CalendarContract.Events#CONTENT_URI 446 Events.CONTENT_URI}</dd> 447 448 <dt><b>MIME Type</b></dt> 449 <dd>{@code "vnd.android.cursor.dir/event"} 450 </dd> 451 452 <dt><b>Extras</b></dt> 453 <dd> 454 <dl> 455 <dt>{@link android.provider.CalendarContract#EXTRA_EVENT_ALL_DAY}</dt> 456 <dd>A boolean specifying whether this is an all-day event.</dd> 457 <dt>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME}</dt> 458 <dd>The start time of the event (milliseconds since epoch).</dd> 459 <dt>{@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME}</dt> 460 <dd>The end time of the event (milliseconds since epoch).</dd> 461 <dt>{@link android.provider.CalendarContract.EventsColumns#TITLE}</dt> 462 <dd>The event title.</dd> 463 <dt>{@link android.provider.CalendarContract.EventsColumns#DESCRIPTION}</dt> 464 <dd>The event description.</dd> 465 <dt>{@link android.provider.CalendarContract.EventsColumns#EVENT_LOCATION}</dt> 466 <dd>The event location.</dd> 467 <dt>{@link android.content.Intent#EXTRA_EMAIL}</dt> 468 <dd>A comma-separated list of email addresses that specify the invitees.</dd> 469 </dl> 470 <p>Many more event details can be specified using the constants defined in the 471 {@link android.provider.CalendarContract.EventsColumns} class.</p> 472 </dd> 473 474 475 </dl> 476 477 <p><b>Example intent:</b></p> 478 <pre> 479 public void addEvent(String title, String location, Calendar begin, Calendar end) { 480 Intent intent = new Intent(Intent.ACTION_INSERT) 481 .setData(Events.CONTENT_URI) 482 .putExtra(Events.TITLE, title) 483 .putExtra(Events.EVENT_LOCATION, location) 484 .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin) 485 .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end); 486 if (intent.resolveActivity(getPackageManager()) != null) { 487 startActivity(intent); 488 } 489 } 490 </pre> 491 492 493 <p><b>Example intent filter:</b></p> 494 <pre> 495 <activity ...> 496 <intent-filter> 497 <action android:name="android.intent.action.INSERT" /> 498 <data android:mimeType="vnd.android.cursor.dir/event" /> 499 <category android:name="android.intent.category.DEFAULT" /> 500 </intent-filter> 501 </activity> 502 </pre> 503 504 505 506 507 508 509 510 511 512 513 514 515 516 <h2 id="Camera">Camera</h2> 517 518 519 520 <h3 id="ImageCapture">Capture a picture or video and return it</h3> 521 522 <p>To open a camera app and receive the resulting photo or video, use the {@link 523 android.provider.MediaStore#ACTION_IMAGE_CAPTURE} or {@link 524 android.provider.MediaStore#ACTION_VIDEO_CAPTURE} action. Also specify the URI location where you'd 525 like the camera to save the photo or video, in the {@link android.provider.MediaStore#EXTRA_OUTPUT} 526 extra.</p> 527 528 529 <dl> 530 <dt><b>Action</b></dt> 531 <dd>{@link android.provider.MediaStore#ACTION_IMAGE_CAPTURE} or<br> 532 {@link android.provider.MediaStore#ACTION_VIDEO_CAPTURE}</dd> 533 534 <dt><b>Data URI Scheme</b></dt> 535 <dd>None</dd> 536 537 <dt><b>MIME Type</b></dt> 538 <dd>None</dd> 539 540 <dt><b>Extras</b></dt> 541 <dd> 542 <dl> 543 <dt>{@link android.provider.MediaStore#EXTRA_OUTPUT}</dt> 544 <dd>The URI location where the camera app should save the photo or 545 video file (as a {@link android.net.Uri} object).</dd> 546 </dl> 547 </dd> 548 </dl> 549 550 <p>When the camera app successfully returns 551 focus to your activity (your app receives the {@link android.app.Activity#onActivityResult 552 onActivityResult()} callback), you can access the photo or video at the URI you specified 553 with the {@link android.provider.MediaStore#EXTRA_OUTPUT} value.</p> 554 555 <p class="note"><strong>Note:</strong> When you use {@link 556 android.provider.MediaStore#ACTION_IMAGE_CAPTURE} to capture a photo, the camera may also return a 557 downscaled copy (a thumbnail) of the photo in the result {@link 558 android.content.Intent}, saved as a {@link android.graphics.Bitmap} in an extra field named 559 <code>"data"</code>.</p> 560 561 562 <p><b>Example intent:</b></p> 563 <pre> 564 static final int REQUEST_IMAGE_CAPTURE = 1; 565 static final Uri mLocationForPhotos; 566 567 public void capturePhoto(String targetFilename) { 568 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 569 intent.putExtra(MediaStore.EXTRA_OUTPUT, 570 Uri.withAppendedPath(mLocationForPhotos, targetFilename); 571 if (intent.resolveActivity(getPackageManager()) != null) { 572 startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); 573 } 574 } 575 576 @Override 577 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 578 if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { 579 Bitmap thumbnail = data.getParcelable("data"); 580 // Do other work with full size photo saved in mLocationForPhotos 581 ... 582 } 583 } 584 </pre> 585 586 <p>For more information about how to use this intent to capture a photo, including 587 how to create an appropriate {@link android.net.Uri} for the output location, read 588 <a href="{@docRoot}training/camera/photobasics.html">Taking Photos Simply</a> or 589 <a href="{@docRoot}training/camera/videobasics.html">Taking Videos Simply</a>.</p> 590 591 <p><b>Example intent filter:</b></p> 592 <pre> 593 <activity ...> 594 <intent-filter> 595 <action android:name="android.media.action.IMAGE_CAPTURE" /> 596 <category android:name="android.intent.category.DEFAULT" /> 597 </intent-filter> 598 </activity> 599 </pre> 600 601 <p>When handling this intent, your activity should check for the {@link 602 android.provider.MediaStore#EXTRA_OUTPUT} extra in the incoming {@link android.content.Intent}, 603 then save the captured image or video at the location specified by that extra and call {@link 604 android.app.Activity#setResult(int,Intent) setResult()} with an 605 {@link android.content.Intent} that includes a compressed thumbnail 606 in an extra named <code>"data"</code>.</p> 607 608 609 610 <h3 id="CameraStill">Start a camera app in still image mode</h3> 611 612 <!-- Google Now box --> 613 <div class="now-box"> 614 <div class="now-img-cont"> 615 <a href="#Now"> 616 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 617 width="30" height="30" alt=""/> 618 </a> 619 </div> 620 <p class="now-title">Google Now</p> 621 <ul> 622 <li>"take a picture"</li> 623 </ul> 624 </div> 625 626 <p>To open a camera app in still image mode, use the {@link 627 android.provider.MediaStore#INTENT_ACTION_STILL_IMAGE_CAMERA} action.</p> 628 629 <dl> 630 <dt><b>Action</b></dt> 631 <dd>{@link android.provider.MediaStore#INTENT_ACTION_STILL_IMAGE_CAMERA}</dd> 632 633 <dt><b>Data URI Scheme</b></dt> 634 <dd>None</dd> 635 636 <dt><b>MIME Type</b></dt> 637 <dd>None</dd> 638 639 <dt><b>Extras</b></dt> 640 <dd>None</dd> 641 </dl> 642 643 644 <p><b>Example intent:</b></p> 645 <pre> 646 public void capturePhoto() { 647 Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); 648 if (intent.resolveActivity(getPackageManager()) != null) { 649 startActivityForResult(intent); 650 } 651 } 652 </pre> 653 654 <p><b>Example intent filter:</b></p> 655 <pre> 656 <activity ...> 657 <intent-filter> 658 <action android:name="android.media.action.STILL_IMAGE_CAMERA" /> 659 <category android:name="android.intent.category.DEFAULT" /> 660 </intent-filter> 661 </activity> 662 </pre> 663 664 665 666 <h3 id="CameraVideo">Start a camera app in video mode</h3> 667 668 <!-- Google Now box --> 669 <div class="now-box"> 670 <div class="now-img-cont"> 671 <a href="#Now"> 672 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 673 width="30" height="30" alt=""/> 674 </a> 675 </div> 676 <p class="now-title">Google Now</p> 677 <ul> 678 <li>"record a video"</li> 679 </ul> 680 </div> 681 682 <p>To open a camera app in video mode, use the {@link 683 android.provider.MediaStore#INTENT_ACTION_VIDEO_CAMERA} action.</p> 684 685 <dl> 686 <dt><b>Action</b></dt> 687 <dd>{@link android.provider.MediaStore#INTENT_ACTION_VIDEO_CAMERA}</dd> 688 689 <dt><b>Data URI Scheme</b></dt> 690 <dd>None</dd> 691 692 <dt><b>MIME Type</b></dt> 693 <dd>None</dd> 694 695 <dt><b>Extras</b></dt> 696 <dd>None</dd> 697 </dl> 698 699 700 <p><b>Example intent:</b></p> 701 <pre> 702 public void capturePhoto() { 703 Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 704 if (intent.resolveActivity(getPackageManager()) != null) { 705 startActivityForResult(intent); 706 } 707 } 708 </pre> 709 710 <p><b>Example intent filter:</b></p> 711 <pre> 712 <activity ...> 713 <intent-filter> 714 <action android:name="android.media.action.VIDEO_CAMERA" /> 715 <category android:name="android.intent.category.DEFAULT" /> 716 </intent-filter> 717 </activity> 718 </pre> 719 720 721 722 723 724 <h2 id="Contacts">Contacts/People App</h2> 725 726 727 <h3 id="PickContact">Select a contact</h3> 728 729 <p>To have the user select a contact and provide your app access to all the contact information, 730 use the {@link android.content.Intent#ACTION_PICK} action and specify the MIME type to 731 {@link android.provider.ContactsContract.Contacts#CONTENT_TYPE 732 Contacts.CONTENT_TYPE}.</p> 733 734 <p>The result {@link android.content.Intent} delivered to your {@link 735 android.app.Activity#onActivityResult onActivityResult()} callback contains the 736 <code>content:</code> URI pointing to the selected contact. The response grants 737 your app temporary permissions to read that contact using the <a 738 href="{@docRoot}guide/topics/providers/contacts-provider.html">Contacts Provider</a> API even if 739 your app does not include the {@link android.Manifest.permission#READ_CONTACTS} permission.</p> 740 741 <p class="note"><strong>Tip:</strong> If you need access to only a specific piece of contact 742 information, such as a phone number or email address, instead see the next section about how to 743 <a href="#PickContactData">select specific contact data</a>.</p> 744 745 <dl> 746 <dt><b>Action</b></dt> 747 <dd>{@link android.content.Intent#ACTION_PICK}</dd> 748 749 <dt><b>Data URI Scheme</b></dt> 750 <dd>None</dd> 751 752 <dt><b>MIME Type</b></dt> 753 <dd>{@link android.provider.ContactsContract.Contacts#CONTENT_TYPE 754 Contacts.CONTENT_TYPE} 755 </dd> 756 </dl> 757 758 <p><b>Example intent:</b></p> 759 <pre> 760 static final int REQUEST_SELECT_CONTACT = 1; 761 762 public void selectContact() { 763 Intent intent = new Intent(Intent.ACTION_PICK); 764 intent.setType(ContactsContract.Contacts.CONTENT_TYPE); 765 if (intent.resolveActivity(getPackageManager()) != null) { 766 startActivityForResult(intent, REQUEST_SELECT_CONTACT); 767 } 768 } 769 770 @Override 771 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 772 if (requestCode == REQUEST_SELECT_CONTACT && resultCode == RESULT_OK) { 773 Uri contactUri = data.getData(); 774 // Do something with the selected contact at contactUri 775 ... 776 } 777 } 778 </pre> 779 780 <p>For information about how to retrieve contact details once you have the contact URI, 781 read <a href="{@docRoot}training/contacts-provider/retrieve-details.html">Retrieving Details 782 for a Contact</a>. Remember, when you retrieve the contact URI with the above intent, you 783 <strong>do not</strong> need the {@link android.Manifest.permission#READ_CONTACTS} permission 784 to read details for that contact.</p> 785 786 787 788 789 <h3 id="PickContactDat">Select specific contact data</h3> 790 791 <p>To have the user select a specific piece of information from a contact, such as 792 a phone number, email address, or other data type, use the 793 {@link android.content.Intent#ACTION_PICK} action and specify the MIME type to one 794 of the content types listed below, such as 795 {@link android.provider.ContactsContract.CommonDataKinds.Phone#CONTENT_TYPE 796 CommonDataKinds.Phone.CONTENT_TYPE} to get the contact's phone number.</p> 797 798 <p>If you need to retrieve only one type of data from a contact, this technique with a 799 {@code CONTENT_TYPE} from the 800 {@link android.provider.ContactsContract.CommonDataKinds} classes is more efficient than 801 using the {@link android.provider.ContactsContract.Contacts#CONTENT_TYPE 802 Contacts.CONTENT_TYPE} (as shown in the previous section) because the result provides you direct 803 access to the desired data without requiring you to perform a more complex query to <a 804 href="{@docRoot}guide/topics/providers/contacts-provider.html">Contacts Provider</a>.</p> 805 806 <p>The result {@link android.content.Intent} delivered to your {@link 807 android.app.Activity#onActivityResult onActivityResult()} callback contains the 808 <code>content:</code> URI pointing to the selected contact data. The response grants 809 your app temporary permissions to read that contact data even if your app does 810 not include the {@link android.Manifest.permission#READ_CONTACTS} permission.</p> 811 812 <dl> 813 <dt><b>Action</b></dt> 814 <dd>{@link android.content.Intent#ACTION_PICK}</dd> 815 816 <dt><b>Data URI Scheme</b></dt> 817 <dd>None</dd> 818 819 <dt><b>MIME Type</b></dt> 820 <dd> 821 <dl> 822 <dt>{@link android.provider.ContactsContract.CommonDataKinds.Phone#CONTENT_TYPE 823 CommonDataKinds.Phone.CONTENT_TYPE}</dt> 824 <dd>Pick from contacts with a phone number.</dd> 825 <dt>{@link android.provider.ContactsContract.CommonDataKinds.Email#CONTENT_TYPE 826 CommonDataKinds.Email.CONTENT_TYPE}</dt> 827 <dd>Pick from contacts with an email address.</dd> 828 <dt>{@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#CONTENT_TYPE 829 CommonDataKinds.StructuredPostal.CONTENT_TYPE}</dt> 830 <dd>Pick from contacts with a postal address.</dd> 831 </dl> 832 <p>Or one of many other {@code CONTENT_TYPE} values 833 under {@link android.provider.ContactsContract}.</p> 834 </dd> 835 </dl> 836 837 <p><b>Example intent:</b></p> 838 <pre> 839 static final int REQUEST_SELECT_PHONE_NUMBER = 1; 840 841 public void selectContact() { 842 // Start an activity for the user to pick a phone number from contacts 843 Intent intent = new Intent(Intent.ACTION_PICK); 844 intent.setType(CommonDataKinds.Phone.CONTENT_TYPE); 845 if (intent.resolveActivity(getPackageManager()) != null) { 846 startActivityForResult(intent, REQUEST_SELECT_PHONE_NUMBER); 847 } 848 } 849 850 @Override 851 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 852 if (requestCode == REQUEST_SELECT_PHONE_NUMBER && resultCode == RESULT_OK) { 853 // Get the URI and query the content provider for the phone number 854 Uri contactUri = data.getData(); 855 String[] projection = new String[]{CommonDataKinds.Phone.NUMBER}; 856 Cursor cursor = getContentResolver().query(contactUri, projection, 857 null, null, null); 858 // If the cursor returned is valid, get the phone number 859 if (cursor != null && cursor.moveToFirst()) { 860 int numberIndex = cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER); 861 String number = cursor.getString(numberIndex); 862 // Do something with the phone number 863 ... 864 } 865 } 866 } 867 </pre> 868 869 870 871 872 873 <h3 id="ViewContact">View a contact</h3> 874 875 <p>To display the details for a known contact, use the {@link android.content.Intent#ACTION_VIEW} 876 action and specify the contact with a {@code content:} URI as the intent data.</p> 877 878 <p>There are primarily two ways to initially retrieve the contact's URI:</p> 879 <ul> 880 <li>Use the contact URI returned by the {@link android.content.Intent#ACTION_PICK}, 881 shown in the previous section (this approach does not require any app permissions).</li> 882 <li>Access the list of all contacts directly, as described in <a 883 href="{@docRoot}training/contacts-provider/retrieve-names.html">Retrieving a List of 884 Contacts</a> (this approach requires the {@link android.Manifest.permission#READ_CONTACTS} 885 permission).</li> 886 </ul> 887 888 <dl> 889 <dt><b>Action</b></dt> 890 <dd>{@link android.content.Intent#ACTION_VIEW}</dd> 891 892 <dt><b>Data URI Scheme</b></dt> 893 <dd>{@code content:<URI>}</dd> 894 895 <dt><b>MIME Type</b></dt> 896 <dd>None. The type is inferred from contact URI. 897 </dd> 898 </dl> 899 900 <p><b>Example intent:</b></p> 901 <pre> 902 public void viewContact(Uri contactUri) { 903 Intent intent = new Intent(Intent.ACTION_VIEW, contactUri); 904 if (intent.resolveActivity(getPackageManager()) != null) { 905 startActivity(intent); 906 } 907 } 908 </pre> 909 910 911 912 <h3 id="EditContact">Edit an existing contact</h3> 913 914 <p>To edit a known contact, use the {@link android.content.Intent#ACTION_EDIT} 915 action, specify the contact with a {@code content:} URI 916 as the intent data, and include any known contact information in extras specified by 917 constants in {@link android.provider.ContactsContract.Intents.Insert}.</p> 918 919 <p>There are primarily two ways to initially retrieve the contact URI:</p> 920 <ul> 921 <li>Use the contact URI returned by the {@link android.content.Intent#ACTION_PICK}, 922 shown in the previous section (this approach does not require any app permissions).</li> 923 <li>Access the list of all contacts directly, as described in <a 924 href="{@docRoot}training/contacts-provider/retrieve-names.html">Retrieving a List of 925 Contacts</a> (this approach requires the {@link android.Manifest.permission#READ_CONTACTS} 926 permission).</li> 927 </ul> 928 929 <dl> 930 <dt><b>Action</b></dt> 931 <dd>{@link android.content.Intent#ACTION_EDIT}</dd> 932 933 <dt><b>Data URI Scheme</b></dt> 934 <dd>{@code content:<URI>}</dd> 935 936 <dt><b>MIME Type</b></dt> 937 <dd>The type is inferred from contact URI. 938 </dd> 939 940 <dt><b>Extras</b></dt> 941 <dd>One or more of the extras defined in {@link android.provider.ContactsContract.Intents.Insert} 942 so you can populate fields of the contact details. 943 </dd> 944 </dl> 945 946 <p><b>Example intent:</b></p> 947 <pre> 948 public void editContact(Uri contactUri, String email) { 949 Intent intent = new Intent(Intent.ACTION_EDIT); 950 intent.setData(contactUri); 951 intent.putExtra(Intents.Insert.EMAIL, email); 952 if (intent.resolveActivity(getPackageManager()) != null) { 953 startActivity(intent); 954 } 955 } 956 </pre> 957 958 <p>For more information about how to edit a contact, read <a 959 href="{@docRoot}training/contacts-provider/modify-data.html">Modifying 960 Contacts Using Intents</a>.</p> 961 962 963 964 965 <h3 id="InsertContact">Insert a contact</h3> 966 967 <p>To insert a new contact, use the {@link android.content.Intent#ACTION_INSERT} action, 968 specify {@link android.provider.ContactsContract.Contacts#CONTENT_TYPE Contacts.CONTENT_TYPE} as 969 the MIME type, and include any known contact information in extras specified by 970 constants in {@link android.provider.ContactsContract.Intents.Insert}. 971 972 <dl> 973 <dt><b>Action</b></dt> 974 <dd>{@link android.content.Intent#ACTION_INSERT}</dd> 975 976 <dt><b>Data URI Scheme</b></dt> 977 <dd>None</dd> 978 979 <dt><b>MIME Type</b></dt> 980 <dd>{@link android.provider.ContactsContract.Contacts#CONTENT_TYPE Contacts.CONTENT_TYPE}</dd> 981 982 <dt><b>Extras</b></dt> 983 <dd>One or more of the extras defined in {@link android.provider.ContactsContract.Intents.Insert}. 984 </dd> 985 </dl> 986 987 <p><b>Example intent:</b></p> 988 <pre> 989 public void insertContact(String name, String email) { 990 Intent intent = new Intent(Intent.ACTION_INSERT); 991 intent.setType(Contacts.CONTENT_TYPE); 992 intent.putExtra(Intents.Insert.NAME, name); 993 intent.putExtra(Intents.Insert.EMAIL, email); 994 if (intent.resolveActivity(getPackageManager()) != null) { 995 startActivity(intent); 996 } 997 } 998 </pre> 999 1000 <p>For more information about how to insert a contact, read <a 1001 href="{@docRoot}training/contacts-provider/modify-data.html">Modifying 1002 Contacts Using Intents</a>.</p> 1003 1004 1005 1006 1007 1008 1009 1010 <h2 id="Email">Email</h2> 1011 1012 1013 <h3 id="ComposeEmail">Compose an email with optional attachments</h3> 1014 1015 <p>To compose an email, use one of the below actions based on whether you'll include attachments, 1016 and include email details such as the recipient and subject using the extra keys listed below.</p> 1017 1018 <dl> 1019 <dt><b>Action</b></dt> 1020 <dd>{@link android.content.Intent#ACTION_SENDTO} (for no attachment) or<br> 1021 {@link android.content.Intent#ACTION_SEND} (for one attachment) or<br> 1022 {@link android.content.Intent#ACTION_SEND_MULTIPLE} (for multiple attachments)</dd> 1023 1024 <dt><b>Data URI Scheme</b></dt> 1025 <dd>None</dd> 1026 1027 <dt><b>MIME Type</b></dt> 1028 <dd> 1029 <dl> 1030 <dt>{@link org.apache.http.protocol.HTTP#PLAIN_TEXT_TYPE} ("text/plain") 1031 <dt><code>"*/*"</code> 1032 </dl> 1033 </dd> 1034 1035 <dt><b>Extras</b></dt> 1036 <dd> 1037 <dl> 1038 <dt>{@link android.content.Intent#EXTRA_EMAIL Intent.EXTRA_EMAIL}</dt> 1039 <dd>A string array of all "To" recipient email addresses.</dd> 1040 <dt>{@link android.content.Intent#EXTRA_CC Intent.EXTRA_CC}</dt> 1041 <dd>A string array of all "CC" recipient email addresses.</dd> 1042 <dt>{@link android.content.Intent#EXTRA_BCC Intent.EXTRA_BCC}</dt> 1043 <dd>A string array of all "BCC" recipient email addresses.</dd> 1044 <dt>{@link android.content.Intent#EXTRA_SUBJECT Intent.EXTRA_SUBJECT}</dt> 1045 <dd>A string with the email subject.</dd> 1046 <dt>{@link android.content.Intent#EXTRA_TEXT Intent.EXTRA_TEXT}</dt> 1047 <dd>A string with the body of the email.</dd> 1048 <dt>{@link android.content.Intent#EXTRA_STREAM Intent.EXTRA_STREAM}</dt> 1049 <dd>A {@link android.net.Uri} pointing to the attachment. If using the 1050 {@link android.content.Intent#ACTION_SEND_MULTIPLE} action, this should instead 1051 be an {@link java.util.ArrayList} containing multiple {@link android.net.Uri} objects.</dd> 1052 </dl> 1053 </dd> 1054 1055 </dl> 1056 1057 1058 <p><b>Example intent:</b></p> 1059 <pre> 1060 public void composeEmail(String[] addresses, String subject, Uri attachment) { 1061 Intent intent = new Intent(Intent.ACTION_SEND); 1062 intent.setType("*/*"); 1063 intent.putExtra(Intent.EXTRA_EMAIL, addresses); 1064 intent.putExtra(Intent.EXTRA_SUBJECT, subject); 1065 intent.putExtra(Intent.EXTRA_STREAM, attachment); 1066 if (intent.resolveActivity(getPackageManager()) != null) { 1067 startActivity(intent); 1068 } 1069 } 1070 </pre> 1071 1072 <p>If you want to ensure that your intent is handled only by an email app (and not other 1073 text messaging or social apps), then use the {@link android.content.Intent#ACTION_SENDTO} action 1074 and include the {@code "mailto:"} data scheme. For example:</p> 1075 1076 <pre> 1077 public void composeEmail(String[] addresses, String subject) { 1078 Intent intent = new Intent(Intent.ACTION_SENDTO); 1079 intent.setData(Uri.parse("mailto:")); // only email apps should handle this 1080 intent.putExtra(Intent.EXTRA_EMAIL, addresses); 1081 intent.putExtra(Intent.EXTRA_SUBJECT, subject); 1082 if (intent.resolveActivity(getPackageManager()) != null) { 1083 startActivity(intent); 1084 } 1085 } 1086 </pre> 1087 1088 1089 <p><b>Example intent filter:</b></p> 1090 <pre> 1091 <activity ...> 1092 <intent-filter> 1093 <action android:name="android.intent.action.SEND" /> 1094 <data android:type="*/*" /> 1095 <category android:name="android.intent.category.DEFAULT" /> 1096 </intent-filter> 1097 <intent-filter> 1098 <action android:name="android.intent.action.SENDTO" /> 1099 <data android:scheme="mailto" /> 1100 <category android:name="android.intent.category.DEFAULT" /> 1101 </intent-filter> 1102 </activity> 1103 </pre> 1104 1105 1106 1107 1108 1109 1110 1111 <h2 id="Storage">File Storage</h2> 1112 1113 1114 1115 <h3 id="GetFile">Retrieve a specific type of file</h3> 1116 1117 <p>To request that the user select a file such as a document or photo and return a reference to 1118 your app, use the {@link android.content.Intent#ACTION_GET_CONTENT} action and specify your desired 1119 MIME type. The file reference returned to your app is transient to your activity's current 1120 lifecycle, so if you want to access it later you must import a copy that you can read later. 1121 This intent also allows the user to create a new file in the process (for 1122 example, instead of selecting an existing photo, the user can capture a new photo with the camera). 1123 </p> 1124 1125 <p>The result intent delivered to your {@link android.app.Activity#onActivityResult 1126 onActivityResult()} method includes data with a URI pointing to the file. 1127 The URI could be anything, such as an {@code http:} URI, {@code file:} URI, or {@code content:} 1128 URI. However, if you'd like to restrict selectable files to only those that are accessible 1129 from a content provider (a {@code content:} URI) and that are available as a file stream with {@link 1130 android.content.ContentResolver#openFileDescriptor openFileDescriptor()}, you should add 1131 the {@link android.content.Intent#CATEGORY_OPENABLE} category to your intent.</p> 1132 1133 <p>On Android 4.3 (API level 18) and higher, 1134 you can also allow the user to select multiple files by adding 1135 {@link android.content.Intent#EXTRA_ALLOW_MULTIPLE} to the intent, set to {@code true}. 1136 You can then access each of the selected files in a {@link android.content.ClipData} 1137 object returned by {@link android.content.Intent#getClipData()}.</p> 1138 1139 1140 <dl> 1141 <dt><b>Action</b></dt> 1142 <dd>{@link android.content.Intent#ACTION_GET_CONTENT}</dd> 1143 1144 <dt><b>Data URI Scheme</b></dt> 1145 <dd>None</dd> 1146 1147 <dt><b>MIME Type</b></dt> 1148 <dd>The MIME type corresponding to the file type the user should select. 1149 </dd> 1150 1151 <dt><b>Extras</b></dt> 1152 <dd> 1153 <dl> 1154 <dt>{@link android.content.Intent#EXTRA_ALLOW_MULTIPLE} 1155 <dd>A boolean declaring whether the user can select more than one file at a time. 1156 </dd> 1157 <dt>{@link android.content.Intent#EXTRA_LOCAL_ONLY} 1158 <dd>A boolean that declares whether the returned file must be available directly from 1159 the device, rather than requiring a download from a remote service. 1160 </dd> 1161 </dl> 1162 </dd> 1163 1164 <dt><b>Category</b> (optional)</dt> 1165 <dd> 1166 <dl> 1167 <dt>{@link android.content.Intent#CATEGORY_OPENABLE}</dt> 1168 <dd>To return only "openable" files that can be represented as a file stream 1169 with {@link android.content.ContentResolver#openFileDescriptor openFileDescriptor()}.</dd> 1170 </dl> 1171 </dd> 1172 1173 </dl> 1174 1175 <p><b>Example intent to get a photo:</b></p> 1176 <pre> 1177 static final int REQUEST_IMAGE_GET = 1; 1178 1179 public void selectImage() { 1180 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 1181 intent.setType("image/*"); 1182 if (intent.resolveActivity(getPackageManager()) != null) { 1183 startActivityForResult(intent, REQUEST_IMAGE_GET); 1184 } 1185 } 1186 1187 @Override 1188 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 1189 if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) { 1190 Bitmap thumbnail = data.getParcelable("data"); 1191 Uri fullPhotoUri = data.getData(); 1192 // Do work with photo saved at fullPhotoUri 1193 ... 1194 } 1195 } 1196 </pre> 1197 1198 <p><b>Example intent filter to return a photo:</b></p> 1199 <pre> 1200 <activity ...> 1201 <intent-filter> 1202 <action android:name="android.intent.action.GET_CONTENT" /> 1203 <data android:type="image/*" /> 1204 <category android:name="android.intent.category.DEFAULT" /> 1205 <!-- The OPENABLE category declares that the returned file is accessible 1206 from a content provider that supports {@link android.provider.OpenableColumns} 1207 and {@link android.content.ContentResolver#openFileDescriptor ContentResolver.openFileDescriptor()} --> 1208 <category android:name="android.intent.category.OPENABLE" /> 1209 </intent-filter> 1210 </activity> 1211 </pre> 1212 1213 1214 1215 1216 1217 1218 <h3 id="OpenFile">Open a specific type of file</h3> 1219 1220 <p>Instead of retrieving a copy of a file that you must import to your app 1221 (by using the {@link android.content.Intent#ACTION_GET_CONTENT} action), when running on Android 1222 4.4 or higher, you can instead request to <em>open</em> a file that's managed by another app by 1223 using the {@link android.content.Intent#ACTION_OPEN_DOCUMENT} action and specifying a MIME type. 1224 To also allow the user to instead create a new document that your app can write to, use the {@link 1225 android.content.Intent#ACTION_CREATE_DOCUMENT} action instead. For example, instead of 1226 selecting from existing PDF documents, the {@link android.content.Intent#ACTION_CREATE_DOCUMENT} 1227 intent allows users to select where they'd like to create a new document (within another app 1228 that manages the document's storage)—your app then receives the URI location of where it 1229 can write the new document.</p> 1230 1231 <p>Whereas the intent delivered to your {@link android.app.Activity#onActivityResult 1232 onActivityResult()} method from the {@link android.content.Intent#ACTION_GET_CONTENT} action may 1233 return a URI of any type, the result intent from {@link android.content.Intent#ACTION_OPEN_DOCUMENT} 1234 and {@link android.content.Intent#ACTION_CREATE_DOCUMENT} always specify the chosen file as a {@code 1235 content:} URI that's backed by a {@link android.provider.DocumentsProvider}. You can open the 1236 file with {@link android.content.ContentResolver#openFileDescriptor openFileDescriptor()} and 1237 query its details using columns from {@link android.provider.DocumentsContract.Document}.</p> 1238 1239 <p>The returned URI grants your app long-term read access to the file (also possibly 1240 with write access). So the {@link android.content.Intent#ACTION_OPEN_DOCUMENT} action is 1241 particularly useful (instead of using {@link android.content.Intent#ACTION_GET_CONTENT}) 1242 when you want to read an existing file without making a copy into your app, 1243 or when you want to open and edit a file in place.</p> 1244 1245 <p>You can also allow the user to select multiple files by adding 1246 {@link android.content.Intent#EXTRA_ALLOW_MULTIPLE} to the intent, set to {@code true}. 1247 If the user selects just one item, then you can retrieve the item from {@link 1248 android.content.Intent#getData()}. If the user selects more than one item, then {@link 1249 android.content.Intent#getData()} returns null and you must instead 1250 retrieve each item from a {@link android.content.ClipData} 1251 object that is returned by {@link android.content.Intent#getClipData()}.</p> 1252 1253 <p class="note"><strong>Note:</strong> Your intent <strong>must</strong> specify a MIME type and 1254 <strong>must</strong> declare the {@link android.content.Intent#CATEGORY_OPENABLE} category. If 1255 appropriate, you can specify more than one MIME type by adding an array of MIME types with the 1256 {@link android.content.Intent#EXTRA_MIME_TYPES} extra—if you do so, you must set the 1257 primary MIME type in {@link android.content.Intent#setType setType()} to {@code "*/*"}.</p> 1258 1259 <dl> 1260 <dt><b>Action</b></dt> 1261 <dd>{@link android.content.Intent#ACTION_OPEN_DOCUMENT} or<br/> 1262 {@link android.content.Intent#ACTION_CREATE_DOCUMENT}</dd> 1263 1264 <dt><b>Data URI Scheme</b></dt> 1265 <dd>None</dd> 1266 1267 <dt><b>MIME Type</b></dt> 1268 <dd>The MIME type corresponding to the file type the user should select. 1269 </dd> 1270 1271 <dt><b>Extras</b></dt> 1272 <dd> 1273 <dl> 1274 <dt>{@link android.content.Intent#EXTRA_MIME_TYPES} 1275 <dd>An array of MIME types corresponding to the types of files your app is 1276 requesting. When you use this extra, you must set the primary MIME type in 1277 {@link android.content.Intent#setType setType()} to {@code "*/*"}.</dd> 1278 <dt>{@link android.content.Intent#EXTRA_ALLOW_MULTIPLE} 1279 <dd>A boolean that declares whether the user can select more than one file at a time. 1280 </dd> 1281 <dt>{@link android.content.Intent#EXTRA_TITLE} 1282 <dd>For use with {@link android.content.Intent#ACTION_CREATE_DOCUMENT} to specify 1283 an initial file name. 1284 </dd> 1285 <dt>{@link android.content.Intent#EXTRA_LOCAL_ONLY} 1286 <dd>A boolean that declares whether the returned file must be available directly from 1287 the device, rather than requiring a download from a remote service. 1288 </dd> 1289 </dl> 1290 </dd> 1291 1292 <dt><b>Category</b></dt> 1293 <dd> 1294 <dl> 1295 <dt>{@link android.content.Intent#CATEGORY_OPENABLE}</dt> 1296 <dd>To return only "openable" files that can be represented as a file stream 1297 with {@link android.content.ContentResolver#openFileDescriptor openFileDescriptor()}.</dd> 1298 </dl> 1299 </dd> 1300 1301 </dl> 1302 1303 <p><b>Example intent to get a photo:</b></p> 1304 <pre> 1305 static final int REQUEST_IMAGE_OPEN = 1; 1306 1307 public void selectImage() { 1308 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 1309 intent.setType("image/*"); 1310 intent.addCategory(Intent.CATEGORY_OPENABLE); 1311 // Only the system receives the ACTION_OPEN_DOCUMENT, so no need to test. 1312 startActivityForResult(intent, REQUEST_IMAGE_OPEN); 1313 } 1314 1315 @Override 1316 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 1317 if (requestCode == REQUEST_IMAGE_OPEN && resultCode == RESULT_OK) { 1318 Uri fullPhotoUri = data.getData(); 1319 // Do work with full size photo saved at fullPhotoUri 1320 ... 1321 } 1322 } 1323 </pre> 1324 1325 <p>Third party apps cannot actually respond to an intent with the 1326 {@link android.content.Intent#ACTION_OPEN_DOCUMENT} action. Instead, the system receives this 1327 intent and displays all the files available from various apps in a unified user interface.</p> 1328 1329 <p>To provide your app's files in this UI and allow other apps to open them, you must implement 1330 a {@link android.provider.DocumentsProvider} and include an intent filter for 1331 {@link android.provider.DocumentsContract#PROVIDER_INTERFACE} 1332 ({@code "android.content.action.DOCUMENTS_PROVIDER"}). For example: 1333 1334 <pre> 1335 <provider ... 1336 android:grantUriPermissions="true" 1337 android:exported="true" 1338 android:permission="android.permission.MANAGE_DOCUMENTS"> 1339 <intent-filter> 1340 <action android:name="android.content.action.DOCUMENTS_PROVIDER" /> 1341 </intent-filter> 1342 </provider> 1343 </pre> 1344 1345 <p>For more information about how to make the files managed by your app openable from other apps, 1346 read the <a href="{@docRoot}guide/topics/providers/document-provider.html">Storage Access 1347 Framework</a> guide.</p> 1348 1349 1350 1351 1352 1353 1354 1355 1356 <h2 id="Fitness">Fitness</h2> 1357 1358 <h3 id="TrackRide">Start/Stop a bike ride</h3> 1359 1360 <!-- Google Now box --> 1361 <div class="now-box"> 1362 <div class="now-img-cont"> 1363 <a href="#Now"> 1364 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 1365 width="30" height="30" alt=""/> 1366 </a> 1367 </div> 1368 <p class="now-title">Google Now</p> 1369 <ul> 1370 <li>"start cycling"</li> 1371 <li>"start my bike ride"</li> 1372 <li>"stop cycling"</li> 1373 </ul> 1374 </div> 1375 1376 <p>To track a bike ride, use the 1377 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 1378 <code>ACTION_TRACK</code></a> action with the <code>"vnd.google.fitness.activity/biking"</code> 1379 MIME type and set the 1380 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#EXTRA_STATUS"> 1381 <code>EXTRA_STATUS</code></a> extra to 1382 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_ACTIVE"> 1383 <code>STATUS_ACTIVE</code></a> when starting and to 1384 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_COMPLETED"> 1385 <code>STATUS_COMPLETED</code></a> when stopping.</p> 1386 1387 <dl> 1388 <dt><b>Action</b></dt> 1389 <dd><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 1390 <code>ACTION_TRACK</code></a><dd> 1391 1392 <dt><b>Data URI</b></dt> 1393 <dd>None</dd> 1394 1395 <dt><b>MIME Type</b></dt> 1396 <dd><code>"vnd.google.fitness.activity/biking"</code></dd> 1397 1398 <dt><b>Extras</b></dt> 1399 <dd> 1400 <dl> 1401 <dt><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#EXTRA_STATUS"> 1402 <code>EXTRA_STATUS</code></a></dt> 1403 <dd>A string with the value <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_ACTIVE"> 1404 <code>STATUS_ACTIVE</code></a> when starting and 1405 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_COMPLETED"> 1406 <code>STATUS_COMPLETED</code></a> when stopping.</dd> 1407 </dl> 1408 </dd> 1409 </dl> 1410 1411 1412 <p><b>Example intent:</b></p> 1413 <pre> 1414 public void startBikeRide() { 1415 Intent intent = new Intent(FitnessIntents.ACTION_TRACK) 1416 .setType("vnd.google.fitness.activity/biking") 1417 .putExtra(FitnessIntents.EXTRA_STATUS, FitnessIntents.STATUS_ACTIVE); 1418 if (intent.resolveActivity(getPackageManager()) != null) { 1419 startActivity(intent); 1420 } 1421 } 1422 </pre> 1423 1424 1425 <p><b>Example intent filter:</b></p> 1426 <pre> 1427 <activity ...> 1428 <intent-filter> 1429 <action android:name="vnd.google.fitness.TRACK" /> 1430 <data android:mimeType="vnd.google.fitness.activity/biking" /> 1431 <category android:name="android.intent.category.DEFAULT" /> 1432 </intent-filter> 1433 </activity> 1434 </pre> 1435 1436 1437 1438 1439 1440 <h3 id="TrackRun">Start/Stop a run</h3> 1441 1442 <!-- Google Now box --> 1443 <div class="now-box"> 1444 <div class="now-img-cont"> 1445 <a href="#Now"> 1446 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 1447 width="30" height="30" alt=""/> 1448 </a> 1449 </div> 1450 <p class="now-title">Google Now</p> 1451 <ul> 1452 <li>"track my run"</li> 1453 <li>"start running"</li> 1454 <li>"stop running"</li> 1455 </ul> 1456 </div> 1457 1458 <p>To track a run, use the 1459 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 1460 <code>ACTION_TRACK</code></a> action with the <code>"vnd.google.fitness.activity/running"</code> 1461 MIME type and set the 1462 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#EXTRA_STATUS"> 1463 <code>EXTRA_STATUS</code></a> extra to 1464 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_ACTIVE"> 1465 <code>STATUS_ACTIVE</code></a> when starting and to 1466 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_COMPLETED"> 1467 <code>STATUS_COMPLETED</code></a> when stopping.</p> 1468 1469 <dl> 1470 <dt><b>Action</b></dt> 1471 <dd><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 1472 <code>ACTION_TRACK</code></a><dd> 1473 1474 <dt><b>Data URI</b></dt> 1475 <dd>None</dd> 1476 1477 <dt><b>MIME Type</b></dt> 1478 <dd><code>"vnd.google.fitness.activity/running"</code></dd> 1479 1480 <dt><b>Extras</b></dt> 1481 <dd> 1482 <dl> 1483 <dt><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#EXTRA_STATUS"> 1484 <code>EXTRA_STATUS</code></a></dt> 1485 <dd>A string with the value <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_ACTIVE"> 1486 <code>STATUS_ACTIVE</code></a> when starting and 1487 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_COMPLETED"> 1488 <code>STATUS_COMPLETED</code></a> when stopping.</dd> 1489 </dl> 1490 </dd> 1491 </dl> 1492 1493 1494 <p><b>Example intent:</b></p> 1495 <pre> 1496 public void startRun() { 1497 Intent intent = new Intent(FitnessIntents.ACTION_TRACK) 1498 .setType("vnd.google.fitness.activity/running") 1499 .putExtra(FitnessIntents.EXTRA_STATUS, FitnessIntents.STATUS_ACTIVE); 1500 if (intent.resolveActivity(getPackageManager()) != null) { 1501 startActivity(intent); 1502 } 1503 } 1504 </pre> 1505 1506 1507 <p><b>Example intent filter:</b></p> 1508 <pre> 1509 <activity ...> 1510 <intent-filter> 1511 <action android:name="vnd.google.fitness.TRACK" /> 1512 <data android:mimeType="vnd.google.fitness.activity/running" /> 1513 <category android:name="android.intent.category.DEFAULT" /> 1514 </intent-filter> 1515 </activity> 1516 </pre> 1517 1518 1519 1520 1521 <h3 id="TrackWorkout">Start/Stop a workout</h3> 1522 1523 <!-- Google Now box --> 1524 <div class="now-box"> 1525 <div class="now-img-cont"> 1526 <a href="#Now"> 1527 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 1528 width="30" height="30" alt=""/> 1529 </a> 1530 </div> 1531 <p class="now-title">Google Now</p> 1532 <ul> 1533 <li>"start a workout"</li> 1534 <li>"track my workout"</li> 1535 <li>"stop workout"</li> 1536 </ul> 1537 </div> 1538 1539 <p>To track a workout, use the 1540 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 1541 <code>ACTION_TRACK</code></a> action with the <code>"vnd.google.fitness.activity/other"</code> 1542 MIME type and set the 1543 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#EXTRA_STATUS"> 1544 <code>EXTRA_STATUS</code></a> extra to 1545 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_ACTIVE"> 1546 <code>STATUS_ACTIVE</code></a> when starting and to 1547 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_COMPLETED"> 1548 <code>STATUS_COMPLETED</code></a> when stopping.</p> 1549 1550 <dl> 1551 <dt><b>Action</b></dt> 1552 <dd><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 1553 <code>ACTION_TRACK</code></a><dd> 1554 1555 <dt><b>Data URI</b></dt> 1556 <dd>None</dd> 1557 1558 <dt><b>MIME Type</b></dt> 1559 <dd><code>"vnd.google.fitness.activity/other"</code></dd> 1560 1561 <dt><b>Extras</b></dt> 1562 <dd> 1563 <dl> 1564 <dt><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#EXTRA_STATUS"> 1565 <code>EXTRA_STATUS</code></a></dt> 1566 <dd>A string with the value <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_ACTIVE"> 1567 <code>STATUS_ACTIVE</code></a> when starting and 1568 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#STATUS_COMPLETED"> 1569 <code>STATUS_COMPLETED</code></a> when stopping.</dd> 1570 </dl> 1571 </dd> 1572 </dl> 1573 1574 1575 <p><b>Example intent:</b></p> 1576 <pre> 1577 public void startWorkout() { 1578 Intent intent = new Intent(FitnessIntents.ACTION_TRACK) 1579 .setType("vnd.google.fitness.activity/other") 1580 .putExtra(FitnessIntents.EXTRA_STATUS, FitnessIntents.STATUS_ACTIVE); 1581 if (intent.resolveActivity(getPackageManager()) != null) { 1582 startActivity(intent); 1583 } 1584 } 1585 </pre> 1586 1587 1588 <p><b>Example intent filter:</b></p> 1589 <pre> 1590 <activity ...> 1591 <intent-filter> 1592 <action android:name="vnd.google.fitness.TRACK" /> 1593 <data android:mimeType="vnd.google.fitness.activity/other" /> 1594 <category android:name="android.intent.category.DEFAULT" /> 1595 </intent-filter> 1596 </activity> 1597 </pre> 1598 1599 1600 1601 1602 <h3 id="ShowHeartRate">Show heart rate</h3> 1603 1604 <!-- Google Now box --> 1605 <div class="now-box"> 1606 <div class="now-img-cont"> 1607 <a href="#Now"> 1608 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 1609 width="30" height="30" alt=""/> 1610 </a> 1611 </div> 1612 <p class="now-title">Google Now</p> 1613 <ul> 1614 <li>"what's my heart rate?"</li> 1615 <li>"what's my bpm?"</li> 1616 </ul> 1617 </div> 1618 1619 <p>To show the user's heart rate, use the 1620 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_VIEW"> 1621 <code>ACTION_VIEW</code></a> action with the 1622 <code>"vnd.google.fitness.data_type/com.google.heart_rate.bpm"</code> MIME type.</p> 1623 1624 <dl> 1625 <dt><b>Action</b></dt> 1626 <dd><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_VIEW"> 1627 <code>ACTION_VIEW</code></a><dd> 1628 1629 <dt><b>Data URI</b></dt> 1630 <dd>None</dd> 1631 1632 <dt><b>MIME Type</b></dt> 1633 <dd><code>"vnd.google.fitness.data_type/com.google.heart_rate.bpm"</code></dd> 1634 1635 <dt><b>Extras</b></dt> 1636 <dd>None</dd> 1637 </dl> 1638 1639 1640 <p><b>Example intent:</b></p> 1641 <pre> 1642 public void showHeartRate() { 1643 Intent intent = new Intent(FitnessIntents.ACTION_VIEW) 1644 .setType("vnd.google.fitness.data_type/com.google.heart_rate.bpm"); 1645 if (intent.resolveActivity(getPackageManager()) != null) { 1646 startActivity(intent); 1647 } 1648 } 1649 </pre> 1650 1651 1652 <p><b>Example intent filter:</b></p> 1653 <pre> 1654 <activity ...> 1655 <intent-filter> 1656 <action android:name="vnd.google.fitness.VIEW" /> 1657 <data android:mimeType="vnd.google.fitness.data_type/com.google.heart_rate.bpm" /> 1658 <category android:name="android.intent.category.DEFAULT" /> 1659 </intent-filter> 1660 </activity> 1661 </pre> 1662 1663 1664 1665 1666 1667 <h3 id="ShowStepCount">Show step count</h3> 1668 1669 <!-- Google Now box --> 1670 <div class="now-box"> 1671 <div class="now-img-cont"> 1672 <a href="#Now"> 1673 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 1674 width="30" height="30" alt=""/> 1675 </a> 1676 </div> 1677 <p class="now-title">Google Now</p> 1678 <ul> 1679 <li>"how many steps have I taken?"</li> 1680 <li>"what's my step count?"</li> 1681 </ul> 1682 </div> 1683 1684 <p>To show the user's step count, use the 1685 <a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_VIEW"> 1686 <code>ACTION_VIEW</code></a> action with the 1687 <code>"vnd.google.fitness.data_type<br/>/com.google.step_count<br/>.cumulative"</code> MIME 1688 type.</p> 1689 1690 <dl> 1691 <dt><b>Action</b></dt> 1692 <dd><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_VIEW"> 1693 <code>ACTION_VIEW</code></a><dd> 1694 1695 <dt><b>Data URI</b></dt> 1696 <dd>None</dd> 1697 1698 <dt><b>MIME Type</b></dt> 1699 <dd><code>"vnd.google.fitness.data_type/com.google.step_count.cumulative"</code></dd> 1700 1701 <dt><b>Extras</b></dt> 1702 <dd>None</dd> 1703 </dl> 1704 1705 1706 <p><b>Example intent:</b></p> 1707 <pre> 1708 public void showStepCount() { 1709 Intent intent = new Intent(FitnessIntents.ACTION_VIEW) 1710 .setType("vnd.google.fitness.data_type/com.google.step_count.cumulative"); 1711 if (intent.resolveActivity(getPackageManager()) != null) { 1712 startActivity(intent); 1713 } 1714 } 1715 </pre> 1716 1717 1718 <p><b>Example intent filter:</b></p> 1719 <pre> 1720 <activity ...> 1721 <intent-filter> 1722 <action android:name="vnd.google.fitness.VIEW" /> 1723 <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.cumulative" /> 1724 <category android:name="android.intent.category.DEFAULT" /> 1725 </intent-filter> 1726 </activity> 1727 </pre> 1728 1729 1730 1731 1732 1733 1734 1735 1736 <h2 id="Local">Local Actions</h2> 1737 1738 <h3 id="CallCar">Call a car</h3> 1739 1740 <!-- Google Now box --> 1741 <div class="now-box"> 1742 <div class="now-img-cont"> 1743 <a href="#Now"> 1744 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 1745 width="30" height="30" alt=""/> 1746 </a> 1747 </div> 1748 <p class="now-title">Google Now</p> 1749 <ul> 1750 <li>"get me a taxi"</li> 1751 <li>"call me a car"</li> 1752 </ul> 1753 <p style="font-size:13px;margin-bottom:0px;margin-top:10px">(Android Wear only)</p> 1754 </div> 1755 1756 <p>To call a taxi, use the 1757 <a href="{@docRoot}reference/com/google/android/gms/actions/ReserveIntents.html#ACTION_RESERVE_TAXI_RESERVATION"><code>ACTION_RESERVE_TAXI_RESERVATION</code></a> 1758 action.</p> 1759 1760 <p class="note"><strong>Note:</strong> Apps must ask for confirmation from the user 1761 before completing the action.</p> 1762 1763 <dl> 1764 <dt><b>Action</b></dt> 1765 <dd><a href="{@docRoot}reference/com/google/android/gms/actions/ReserveIntents.html#ACTION_RESERVE_TAXI_RESERVATION"><code>ACTION_RESERVE_TAXI_RESERVATION</code></a></dd> 1766 1767 <dt><b>Data URI</b></dt> 1768 <dd>None</dd> 1769 1770 <dt><b>MIME Type</b></dt> 1771 <dd>None</dd> 1772 1773 <dt><b>Extras</b></dt> 1774 <dd>None</dd> 1775 </dl> 1776 1777 1778 <p><b>Example intent:</b></p> 1779 <pre> 1780 public void callCar() { 1781 Intent intent = new Intent(ReserveIntents.ACTION_RESERVE_TAXI_RESERVATION); 1782 if (intent.resolveActivity(getPackageManager()) != null) { 1783 startActivity(intent); 1784 } 1785 } 1786 </pre> 1787 1788 1789 <p><b>Example intent filter:</b></p> 1790 <pre> 1791 <activity ...> 1792 <intent-filter> 1793 <action android:name="com.google.android.gms.actions.RESERVE_TAXI_RESERVATION" /> 1794 <category android:name="android.intent.category.DEFAULT" /> 1795 </intent-filter> 1796 </activity> 1797 </pre> 1798 1799 1800 1801 1802 1803 1804 1805 1806 <h2 id="Maps">Maps</h2> 1807 1808 <h3 id="ViewMap">Show a location on a map</h3> 1809 1810 <p>To open a map, use the {@link android.content.Intent#ACTION_VIEW} action and specify 1811 the location information in the intent data with one of the schemes defined below.</p> 1812 1813 <dl> 1814 <dt><b>Action</b></dt> 1815 <dd>{@link android.content.Intent#ACTION_VIEW}</dd> 1816 1817 <dt><b>Data URI Scheme</b></dt> 1818 <dd> 1819 <dl> 1820 <dt><code>geo:<em>latitude</em>,<em>longitude</em></code></dt> 1821 <dd>Show the map at the given longitude and latitude. 1822 <p>Example: <code>"geo:47.6,-122.3"</code> 1823 </dd> 1824 <dt><code>geo:<em>latitude</em>,<em>longitude</em>?z=<em>zoom</em></code></dt> 1825 <dd>Show the map at the given longitude and latitude at a certain zoom level. A zoom level of 1826 1 shows the whole Earth, centered at the given <em>lat</em>,<em>lng</em>. The highest 1827 (closest) zoom level is 23. 1828 <p>Example: <code>"geo:47.6,-122.3?z=11"</code> 1829 </dd> 1830 <dt><code>geo:0,0?q=lat,lng(label)</code></dt> 1831 <dd>Show the map at the given longitude and latitude with a string label. 1832 <p>Example: <code>"geo:0,0?q=34.99,-106.61(Treasure)"</code> 1833 </dd> 1834 <dt><code>geo:0,0?q=my+street+address</code></dt> 1835 <dd>Show the location for "my street address" (may be a specific address or location query). 1836 <p>Example: <code>"geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA"</code></p> 1837 <p class="note"><strong>Note:</strong> All strings passed in the {@code geo} URI must 1838 be encoded. For example, the string {@code 1st & Pike, Seattle} should become 1839 {@code 1st%20%26%20Pike%2C%20Seattle}. Spaces in the string can be encoded with 1840 {@code %20} or replaced with the plus sign ({@code +}).</p> 1841 </dd> 1842 </dl> 1843 </dd> 1844 1845 <dt><b>MIME Type</b></dt> 1846 <dd>None</dd> 1847 1848 </dl> 1849 1850 <p><b>Example intent:</b></p> 1851 <pre> 1852 public void showMap(Uri geoLocation) { 1853 Intent intent = new Intent(Intent.ACTION_VIEW); 1854 intent.setData(geoLocation); 1855 if (intent.resolveActivity(getPackageManager()) != null) { 1856 startActivity(intent); 1857 } 1858 } 1859 </pre> 1860 1861 <p><b>Example intent filter:</b></p> 1862 <pre> 1863 <activity ...> 1864 <intent-filter> 1865 <action android:name="android.intent.action.VIEW" /> 1866 <data android:scheme="geo" /> 1867 <category android:name="android.intent.category.DEFAULT" /> 1868 </intent-filter> 1869 </activity> 1870 </pre> 1871 1872 1873 1874 1875 1876 1877 1878 1879 <h2 id="Music">Music or Video</h2> 1880 1881 1882 <h3 id="PlayMedia">Play a media file</h3> 1883 1884 <p>To play a music file, use the {@link android.content.Intent#ACTION_VIEW} action and 1885 specify the URI location of the file in the intent data.</p> 1886 1887 <dl> 1888 <dt><b>Action</b></dt> 1889 <dd>{@link android.content.Intent#ACTION_VIEW}</dd> 1890 1891 <dt><b>Data URI Scheme</b></dt> 1892 <dd> 1893 <dl> 1894 <dt>{@code file:<em><URI></em>} 1895 <dt>{@code content:<em><URI></em>} 1896 <dt>{@code http:<em><URL></em>} 1897 </dl> 1898 </dd> 1899 1900 <dt><b>MIME Type</b></dt> 1901 <dd> 1902 <dl> 1903 <dt><code>"audio/*"</code> 1904 <dt><code>"application/ogg"</code> 1905 <dt><code>"application/x-ogg"</code> 1906 <dt><code>"application/itunes"</code> 1907 <dt>Or any other that your app may require. 1908 </dl> 1909 </dd> 1910 1911 </dl> 1912 1913 <p><b>Example intent:</b></p> 1914 <pre> 1915 public void playMedia(Uri file) { 1916 Intent intent = new Intent(Intent.ACTION_VIEW); 1917 intent.setData(file); 1918 if (intent.resolveActivity(getPackageManager()) != null) { 1919 startActivity(intent); 1920 } 1921 } 1922 </pre> 1923 1924 1925 <p><b>Example intent filter:</b></p> 1926 <pre> 1927 <activity ...> 1928 <intent-filter> 1929 <action android:name="android.intent.action.VIEW" /> 1930 <data android:type="audio/*" /> 1931 <data android:type="application/ogg" /> 1932 <category android:name="android.intent.category.DEFAULT" /> 1933 </intent-filter> 1934 </activity> 1935 </pre> 1936 1937 1938 <h3 id="PlaySearch">Play music based on a search query</h3> 1939 1940 <!-- Google Now box --> 1941 <div class="now-box"> 1942 <div class="now-img-cont"> 1943 <a href="#Now"> 1944 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 1945 width="30" height="30" alt=""/> 1946 </a> 1947 </div> 1948 <p class="now-title">Google Now</p> 1949 <ul> 1950 <li>"play michael jackson billie jean"</li> 1951 </ul> 1952 </div> 1953 1954 <p>To play music based on a search query, use the 1955 {@link android.provider.MediaStore#INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH} intent. An app may fire 1956 this intent in response to the user's voice command to play music. The receiving app for this 1957 intent performs a search within its inventory to match existing content to the given query and 1958 starts playing that content.</p> 1959 1960 <p>This intent should include the {@link android.provider.MediaStore#EXTRA_MEDIA_FOCUS} string 1961 extra, which specifies the inteded search mode. For example, the search mode can specify whether 1962 the search is for an artist name or song name.</p> 1963 1964 <dl> 1965 <dt><b>Action</b></dt> 1966 <dd>{@link android.provider.MediaStore#INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH}</dd> 1967 1968 <dt><b>Data URI Scheme</b></dt> 1969 <dd>None</dd> 1970 1971 <dt><b>MIME Type</b></dt> 1972 <dd>None</dd> 1973 1974 <dt><b>Extras</b></dt> 1975 <dd> 1976 <dl> 1977 <dt>{@link android.provider.MediaStore#EXTRA_MEDIA_FOCUS MediaStore.EXTRA_MEDIA_FOCUS} (required)</dt> 1978 <dd> 1979 <p>Indicates the search mode (whether the user is looking for a particular artist, album, song, 1980 or playlist). Most search modes take additional extras. For example, if the user 1981 is interested in listening to a particular song, the intent might have three additional extras: 1982 the song title, the artist, and the album. This intent supports the following search modes for 1983 each value of {@link android.provider.MediaStore#EXTRA_MEDIA_FOCUS}:</p> 1984 <dl> 1985 <dt><p><em>Any</em> - <code>"vnd.android.cursor.item/*"</p></code></dt> 1986 <dd> 1987 <p>Play any music. The receiving app should play some music based on a smart choice, such 1988 as the last playlist the user listened to.</p> 1989 <p>Additional extras:</p> 1990 <ul> 1991 <li>{@link android.app.SearchManager#QUERY} (required) - An empty string. This extra is always 1992 provided for backward compatibility: existing apps that do not know about search modes can 1993 process this intent as an unstructured search.</li> 1994 </ul> 1995 </dd> 1996 <dt><p><em>Unstructured</em> - <code>"vnd.android.cursor.item/*"</code></p></dt> 1997 <dd> 1998 <p>Play a particular song, album or genre from an unstructured search query. Apps may generate 1999 an intent with this search mode when they can't identify the type of content the user wants to 2000 listen to. Apps should use more specific search modes when possible.</p> 2001 <p>Additional extras:</p> 2002 <ul> 2003 <li>{@link android.app.SearchManager#QUERY} (required) - A string that contains any combination 2004 of: the artist, the album, the song name, or the genre.</li> 2005 </ul> 2006 </dd> 2007 <dt><p><em>Genre</em> - 2008 {@link android.provider.MediaStore.Audio.Genres#ENTRY_CONTENT_TYPE Audio.Genres.ENTRY_CONTENT_TYPE}</p></dt> 2009 <dd> 2010 <p>Play music of a particular genre.</p> 2011 <p>Additional extras:</p> 2012 <ul> 2013 <li><code>"android.intent.extra.genre"</code> (required) - The genre.</li> 2014 <li>{@link android.app.SearchManager#QUERY} (required) - The genre. This extra is always provided 2015 for backward compatibility: existing apps that do not know about search modes can process 2016 this intent as an unstructured search.</li> 2017 </ul> 2018 </dd> 2019 <dt><p><em>Artist</em> - 2020 {@link android.provider.MediaStore.Audio.Artists#ENTRY_CONTENT_TYPE Audio.Artists.ENTRY_CONTENT_TYPE}</p></dt> 2021 <dd> 2022 <p>Play music from a particular artist.</p> 2023 <p>Additional extras:</p> 2024 <ul> 2025 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_ARTIST} (required) - The artist.</li> 2026 <li><code>"android.intent.extra.genre"</code> - The genre.</li> 2027 <li>{@link android.app.SearchManager#QUERY} (required) - A string that contains any combination of 2028 the artist or the genre. This extra is always provided for backward compatibility: 2029 existing apps that do not know about search modes can process this intent as an unstructured 2030 search.</li> 2031 </ul> 2032 </dd> 2033 <dt><p><em>Album</em> - 2034 {@link android.provider.MediaStore.Audio.Albums#ENTRY_CONTENT_TYPE Audio.Albums.ENTRY_CONTENT_TYPE}</p></dt> 2035 <dd> 2036 <p>Play music from a particular album.</p> 2037 <p>Additional extras:</p> 2038 <ul> 2039 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_ALBUM} (required) - The album.</li> 2040 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_ARTIST} - The artist.</li> 2041 <li><code>"android.intent.extra.genre"</code> - The genre.</li> 2042 <li>{@link android.app.SearchManager#QUERY} (required) - A string that contains any combination of 2043 the album or the artist. This extra is always provided for backward 2044 compatibility: existing apps that do not know about search modes can process this intent as an 2045 unstructured search.</li> 2046 </ul> 2047 </dd> 2048 <dt><p><em>Song</em> - <code>"vnd.android.cursor.item/audio"</code></p></dt> 2049 <dd> 2050 <p>Play a particular song.</p> 2051 <p>Additional extras:</p> 2052 <ul> 2053 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_ALBUM} - The album.</li> 2054 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_ARTIST} - The artist.</li> 2055 <li><code>"android.intent.extra.genre"</code> - The genre.</li> 2056 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_TITLE} (required) - The song name.</li> 2057 <li>{@link android.app.SearchManager#QUERY} (required) - A string that contains any combination of: 2058 the album, the artist, the genre, or the title. This extra is always provided for 2059 backward compatibility: existing apps that do not know about search modes can process this 2060 intent as an unstructured search.</li> 2061 </ul> 2062 </dd> 2063 <dt><p><em>Playlist</em> - {@link android.provider.MediaStore.Audio.Playlists#ENTRY_CONTENT_TYPE Audio.Playlists.ENTRY_CONTENT_TYPE}</p></dt> 2064 <dd> 2065 <p>Play a particular playlist or a playlist that matches some criteria specified 2066 by additional extras.</p> 2067 <p>Additional extras:</p> 2068 <ul> 2069 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_ALBUM} - The album.</li> 2070 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_ARTIST} - The artist.</li> 2071 <li><code>"android.intent.extra.genre"</code> - The genre.</li> 2072 <li><code>"android.intent.extra.playlist"</code> - The playlist.</li> 2073 <li>{@link android.provider.MediaStore#EXTRA_MEDIA_TITLE} - The song name that the playlist is 2074 based on.</li> 2075 <li>{@link android.app.SearchManager#QUERY} (required) - A string that contains any combination 2076 of: the album, the artist, the genre, the playlist, or the title. This extra is always 2077 provided for backward compatibility: existing apps that do not know about search modes can 2078 process this intent as an unstructured search.</li> 2079 </ul> 2080 </dd> 2081 </dl> 2082 </dd> 2083 </dl> 2084 </dd> 2085 </dl> 2086 2087 2088 2089 <p><b>Example intent:</b></p> 2090 <p>If the user wants to listen to music from a particular artist, a search app may generate the 2091 following intent:</p> 2092 <pre> 2093 public void playSearchArtist(String artist) { 2094 Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH); 2095 intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, 2096 MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE); 2097 intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist); 2098 intent.putExtra(SearchManager.QUERY, artist); 2099 if (intent.resolveActivity(getPackageManager()) != null) { 2100 startActivity(intent); 2101 } 2102 } 2103 </pre> 2104 2105 <p><b>Example intent filter:</b></p> 2106 <pre> 2107 <activity ...> 2108 <intent-filter> 2109 <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" /> 2110 <category android:name="android.intent.category.DEFAULT" /> 2111 </intent-filter> 2112 </activity> 2113 </pre> 2114 <p>When handling this intent, your activity should check the value of the 2115 {@link android.provider.MediaStore#EXTRA_MEDIA_FOCUS} extra in the incoming 2116 {@link android.content.Intent} to determine the search mode. Once your activity has identified 2117 the search mode, it should read the values of the additional extras for that particular search mode. 2118 With this information your app can then perform the search within its inventory to play the 2119 content that matches the search query. For example:</p> 2120 <pre> 2121 protected void onCreate(Bundle savedInstanceState) { 2122 ... 2123 Intent intent = this.getIntent(); 2124 if (intent.getAction().compareTo(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH) == 0) { 2125 2126 String mediaFocus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS); 2127 String query = intent.getStringExtra(SearchManager.QUERY); 2128 2129 // Some of these extras may not be available depending on the search mode 2130 String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM); 2131 String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST); 2132 String genre = intent.getStringExtra("android.intent.extra.genre"); 2133 String playlist = intent.getStringExtra("android.intent.extra.playlist"); 2134 String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE); 2135 2136 // Determine the search mode and use the corresponding extras 2137 if (mediaFocus == null) { 2138 // 'Unstructured' search mode (backward compatible) 2139 playUnstructuredSearch(query); 2140 2141 } else if (mediaFocus.compareTo("vnd.android.cursor.item/*") == 0) { 2142 if (query.isEmpty()) { 2143 // 'Any' search mode 2144 playResumeLastPlaylist(); 2145 } else { 2146 // 'Unstructured' search mode 2147 playUnstructuredSearch(query); 2148 } 2149 2150 } else if (mediaFocus.compareTo(MediaStore.Audio.Genres.ENTRY_CONTENT_TYPE) == 0) { 2151 // 'Genre' search mode 2152 playGenre(genre); 2153 2154 } else if (mediaFocus.compareTo(MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE) == 0) { 2155 // 'Artist' search mode 2156 playArtist(artist, genre); 2157 2158 } else if (mediaFocus.compareTo(MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE) == 0) { 2159 // 'Album' search mode 2160 playAlbum(album, artist); 2161 2162 } else if (mediaFocus.compareTo("vnd.android.cursor.item/audio") == 0) { 2163 // 'Song' search mode 2164 playSong(album, artist, genre, title); 2165 2166 } else if (mediaFocus.compareTo(MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE) == 0) { 2167 // 'Playlist' search mode 2168 playPlaylist(album, artist, genre, playlist, title); 2169 } 2170 } 2171 } 2172 </pre> 2173 2174 2175 2176 2177 <h2 id="Phone">Phone</h2> 2178 2179 2180 <h3 id="DialPhone">Initiate a phone call</h3> 2181 2182 <p>To open the phone app and dial a phone number, use the {@link 2183 android.content.Intent#ACTION_DIAL} action and specify a phone number using 2184 the URI scheme defined below. When the phone app opens, it displays the phone number 2185 but the user must press the <em>Call</em> button to begin the phone call.</p> 2186 2187 <!-- Google Now box --> 2188 <div class="now-box"> 2189 <div class="now-img-cont"> 2190 <a href="#Now"> 2191 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 2192 width="30" height="30" alt=""/> 2193 </a> 2194 </div> 2195 <p class="now-title">Google Now</p> 2196 <ul> 2197 <li>"call 555-5555"</li> 2198 <li>"call bob"</li> 2199 <li>"call voicemail"</li> 2200 </ul> 2201 </div> 2202 2203 <p>To place a phone call directly, use the {@link android.content.Intent#ACTION_CALL} action 2204 and specify a phone number using the URI scheme defined below. When the phone app opens, it 2205 begins the phone call; the user does not need to press the <em>Call</em> button.</p> 2206 2207 <p>The {@link android.content.Intent#ACTION_CALL} action requires that you add the 2208 <code>CALL_PHONE</code> permission to your manifest file:</p> 2209 2210 <pre style="margin-top:45px"> 2211 <uses-permission android:name="android.permission.CALL_PHONE" /> 2212 </pre> 2213 2214 <dl> 2215 <dt><b>Action</b></dt> 2216 <dd> 2217 <ul> 2218 <li>{@link android.content.Intent#ACTION_DIAL} - Opens the dialer or phone app.</li> 2219 <li>{@link android.content.Intent#ACTION_CALL} - Places a phone call (requires the 2220 <code>CALL_PHONE</code> permission)</li> 2221 </ul> 2222 </dd> 2223 2224 <dt><b>Data URI Scheme</b></dt> 2225 <dd> 2226 <ul> 2227 <li>{@code tel:<phone-number>}</li> 2228 <li>{@code voicemail:<phone-number>}</li> 2229 </ul> 2230 </dd> 2231 2232 <dt><b>MIME Type</b></dt> 2233 <dd>None</dd> 2234 2235 </dl> 2236 2237 2238 <p>Valid telephone numbers are those defined 2239 in <a href="http://tools.ietf.org/html/rfc3966">the IETF RFC 3966</a>. 2240 Valid examples include the following:</p> 2241 <ul> 2242 <li><code>tel:2125551212</code> </li> 2243 <li><code>tel:(212) 555 1212</code></li> 2244 </ul> 2245 <p>The Phone's dialer is good at normalizing schemes, such as 2246 telephone numbers. So the scheme described isn't strictly required in the 2247 {@link android.net.Uri#parse(String) Uri.parse()} method. 2248 However, if you have not tried a scheme or are unsure whether it 2249 can be handled, use the {@link android.net.Uri#fromParts Uri.fromParts()} 2250 method instead.</p> 2251 2252 2253 <p><b>Example intent:</b></p> 2254 <pre> 2255 public void dialPhoneNumber(String phoneNumber) { 2256 Intent intent = new Intent(Intent.ACTION_DIAL); 2257 intent.setData(Uri.parse("tel:" + phoneNumber)); 2258 if (intent.resolveActivity(getPackageManager()) != null) { 2259 startActivity(intent); 2260 } 2261 } 2262 </pre> 2263 2264 2265 2266 2267 2268 2269 <h2 id="Search">Search</h2> 2270 2271 <h3 id="SearchOnApp">Search using a specific app</h3> 2272 2273 <!-- Google Now box --> 2274 <div class="now-box"> 2275 <div class="now-img-cont"> 2276 <a href="#Now"> 2277 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 2278 width="30" height="30"/></a> 2279 </div> 2280 <p class="now-title">Google Now</p> 2281 <ul> 2282 <li>"search for cat videos on myvideoapp"</li> 2283 </ul> 2284 </div> 2285 <!-- Video box --> 2286 <a class="notice-developers-video" 2287 href="https://www.youtube.com/watch?v=PS1FbB5qWEI"> 2288 <div> 2289 <h3>Video</h3> 2290 <p>Voice search in your app</p> 2291 </div> 2292 </a> 2293 2294 <p>To support search within the context of your app, declare an intent filter in your app with 2295 the <code>SEARCH_ACTION</code> action, as shown in the example intent filter below.</p> 2296 2297 <dl> 2298 <dt><b>Action</b></dt> 2299 <dd> 2300 <dl> 2301 <dt><code>"com.google.android.gms.actions.SEARCH_ACTION"</code></dt> 2302 <dd>Support search queries from Google Now.</dd> 2303 </dl> 2304 </dd> 2305 2306 <dt><b>Extras</b></dt> 2307 <dd> 2308 <dl> 2309 <dt><code>{@link android.app.SearchManager#QUERY}</code></dt> 2310 <dd>A string that contains the search query.</dd> 2311 <dl> 2312 </dd> 2313 </dl> 2314 2315 <p><b>Example intent filter:</b></p> 2316 <pre> 2317 <activity android:name=".SearchActivity"> 2318 <intent-filter> 2319 <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/> 2320 <category android:name="android.intent.category.DEFAULT"/> 2321 </intent-filter> 2322 </activity> 2323 </pre> 2324 2325 2326 2327 <h3 id="SearchWeb">Perform a web search</h3> 2328 2329 <p>To initiate a web search, use the {@link android.content.Intent#ACTION_WEB_SEARCH} action 2330 and specify the search string in the 2331 {@link android.app.SearchManager#QUERY SearchManager.QUERY} extra.</p> 2332 2333 2334 <dl> 2335 <dt><b>Action</b></dt> 2336 <dd>{@link android.content.Intent#ACTION_WEB_SEARCH}</dd> 2337 2338 <dt><b>Data URI Scheme</b></dt> 2339 <dd>None</dd> 2340 2341 <dt><b>MIME Type</b></dt> 2342 <dd>None</dd> 2343 2344 <dt><b>Extras</b></dt> 2345 <dd> 2346 <dl> 2347 <dt>{@link android.app.SearchManager#QUERY SearchManager.QUERY}</dt> 2348 <dd>The search string.</dd> 2349 </dl> 2350 </dd> 2351 </dl> 2352 2353 <p><b>Example intent:</b></p> 2354 <pre> 2355 public void searchWeb(String query) { 2356 Intent intent = new Intent(Intent.ACTION_SEARCH); 2357 intent.putExtra(SearchManager.QUERY, query); 2358 if (intent.resolveActivity(getPackageManager()) != null) { 2359 startActivity(intent); 2360 } 2361 } 2362 </pre> 2363 2364 2365 2366 2367 2368 2369 2370 <h2 id="Settings">Settings</h2> 2371 2372 <h3 id="OpenSettings">Open a specific section of Settings</h3> 2373 2374 <p>To open a screen in the system settings when your app requires the user to change something, 2375 use one of the following intent actions to open the settings screen respective to the action name. 2376 </p> 2377 2378 <dl> 2379 <dt><b>Action</b></dt> 2380 <dd> 2381 {@link android.provider.Settings#ACTION_SETTINGS}<br/> 2382 {@link android.provider.Settings#ACTION_WIRELESS_SETTINGS}<br/> 2383 {@link android.provider.Settings#ACTION_AIRPLANE_MODE_SETTINGS}<br/> 2384 {@link android.provider.Settings#ACTION_WIFI_SETTINGS}<br/> 2385 {@link android.provider.Settings#ACTION_APN_SETTINGS}<br/> 2386 {@link android.provider.Settings#ACTION_BLUETOOTH_SETTINGS}<br/> 2387 {@link android.provider.Settings#ACTION_DATE_SETTINGS}<br/> 2388 {@link android.provider.Settings#ACTION_LOCALE_SETTINGS}<br/> 2389 {@link android.provider.Settings#ACTION_INPUT_METHOD_SETTINGS}<br/> 2390 {@link android.provider.Settings#ACTION_DISPLAY_SETTINGS}<br/> 2391 {@link android.provider.Settings#ACTION_SECURITY_SETTINGS}<br/> 2392 {@link android.provider.Settings#ACTION_LOCATION_SOURCE_SETTINGS}<br/> 2393 {@link android.provider.Settings#ACTION_INTERNAL_STORAGE_SETTINGS}<br/> 2394 {@link android.provider.Settings#ACTION_MEMORY_CARD_SETTINGS}<br/> 2395 <p>See the {@link android.provider.Settings} documentation for additional settings screens 2396 that are available.</p> 2397 </dd> 2398 2399 <dt><b>Data URI Scheme</b></dt> 2400 <dd>None</dd> 2401 2402 <dt><b>MIME Type</b></dt> 2403 <dd>None</dd> 2404 2405 </dl> 2406 2407 <p><b>Example intent:</b></p> 2408 <pre> 2409 public void openWifiSettings() { 2410 Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS); 2411 if (intent.resolveActivity(getPackageManager()) != null) { 2412 startActivity(intent); 2413 } 2414 } 2415 </pre> 2416 2417 2418 2419 2420 2421 2422 2423 <h2 id="Messaging">Text Messaging</h2> 2424 2425 <h3 id="SendMessage">Compose an SMS/MMS message with attachment</h3> 2426 2427 <p>To initiate an SMS or MMS text message, use one of the intent actions below and specify message 2428 details such as the phone number, subject, and message body using the extra keys listed below.</p> 2429 2430 <dl> 2431 <dt><b>Action</b></dt> 2432 <dd>{@link android.content.Intent#ACTION_SENDTO} or<br> 2433 {@link android.content.Intent#ACTION_SEND} or<br> 2434 {@link android.content.Intent#ACTION_SEND_MULTIPLE}</dd> 2435 2436 <dt><b>Data URI Scheme</b></dt> 2437 <dd> 2438 <dl> 2439 <dt>{@code sms:<em><phone_number></em>} 2440 <dt>{@code smsto:<em><phone_number></em>} 2441 <dt>{@code mms:<em><phone_number></em>} 2442 <dt>{@code mmsto:<em><phone_number></em>} 2443 </dl> 2444 <p>Each of these schemes are handled the same. 2445 </dd> 2446 2447 <dt><b>MIME Type</b></dt> 2448 <dd> 2449 <dl> 2450 <dt>{@link org.apache.http.protocol.HTTP#PLAIN_TEXT_TYPE} (<code>"text/plain"</code>) 2451 <dt><code>"image/*"</code> 2452 <dt><code>"video/*"</code> 2453 </dl> 2454 </dd> 2455 2456 <dt><b>Extras</b></dt> 2457 <dd> 2458 <dl> 2459 <dt><code>"subject"</code></dt> 2460 <dd>A string for the message subject (usually for MMS only).</dd> 2461 <dt><code>"sms_body"</code></dt> 2462 <dd>A string for the text message.</dd> 2463 <dt>{@link android.content.Intent#EXTRA_STREAM}</dt> 2464 <dd>A {@link android.net.Uri} pointing to the 2465 image or video to attach. If using the {@link android.content.Intent#ACTION_SEND_MULTIPLE} action, 2466 this extra should be an {@link java.util.ArrayList} of {@link 2467 android.net.Uri}s pointing to the images/videos to attach.</dd> 2468 <dl> 2469 </dd> 2470 2471 </dl> 2472 2473 <p><b>Example intent:</b></p> 2474 <pre> 2475 public void composeMmsMessage(String message, Uri attachment) { 2476 Intent intent = new Intent(Intent.ACTION_SENDTO); 2477 intent.setType(HTTP.PLAIN_TEXT_TYPE); 2478 intent.putExtra("sms_body", message); 2479 intent.putExtra(Intent.EXTRA_STREAM, attachment); 2480 if (intent.resolveActivity(getPackageManager()) != null) { 2481 startActivity(intent); 2482 } 2483 } 2484 </pre> 2485 2486 <p>If you want to ensure that your intent is handled only by a text messaging app (and not other 2487 email or social apps), then use the {@link android.content.Intent#ACTION_SENDTO} action 2488 and include the {@code "smsto:"} data scheme. For example:</p> 2489 2490 <pre> 2491 public void composeMmsMessage(String message, Uri attachment) { 2492 Intent intent = new Intent(Intent.ACTION_SEND); 2493 intent.setData(Uri.parse("smsto:")); // This ensures only SMS apps respond 2494 intent.putExtra("sms_body", message); 2495 intent.putExtra(Intent.EXTRA_STREAM, attachment); 2496 if (intent.resolveActivity(getPackageManager()) != null) { 2497 startActivity(intent); 2498 } 2499 } 2500 </pre> 2501 2502 2503 <p><b>Example intent filter:</b></p> 2504 <pre> 2505 <activity ...> 2506 <intent-filter> 2507 <action android:name="android.intent.action.SEND" /> 2508 <data android:type="text/plain" /> 2509 <data android:type="image/*" /> 2510 <category android:name="android.intent.category.DEFAULT" /> 2511 </intent-filter> 2512 </activity> 2513 </pre> 2514 2515 <p class="note"><strong>Note:</strong> If you're developing an SMS/MMS messaging app, you must 2516 implement intent filters for several additional actions in order to be available as the 2517 <em>default SMS app</em> on Android 4.4 and higher. For more information, see the documentation 2518 at {@link android.provider.Telephony}.</p> 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 <h2 id="Browser">Web Browser</h2> 2530 2531 <h3 id="ViewUrl">Load a web URL</h3> 2532 2533 <!-- Google Now box --> 2534 <div class="now-box"> 2535 <div class="now-img-cont"> 2536 <a href="#Now"> 2537 <img src="{@docRoot}guide/components/images/voice-icon.png" class="now-img" 2538 width="30" height="30" alt=""/> 2539 </a> 2540 </div> 2541 <p class="now-title">Google Now</p> 2542 <ul> 2543 <li>"open example.com"</li> 2544 </ul> 2545 </div> 2546 2547 <p>To open a web page, use the {@link android.content.Intent#ACTION_VIEW} action 2548 and specify the web URL in the intent data.</p> 2549 2550 <dl> 2551 <dt><b>Action</b></dt> 2552 <dd>{@link android.content.Intent#ACTION_VIEW}<dd> 2553 2554 <dt><b>Data URI Scheme</b></dt> 2555 <dd>{@code http:<em><URL></em>}<br/> 2556 {@code https:<em><URL></em>}</dd> 2557 2558 <dt><b>MIME Type</b></dt> 2559 <dd> 2560 <dl> 2561 <dt>{@link org.apache.http.protocol.HTTP#PLAIN_TEXT_TYPE} (<code>"text/plain"</code>) 2562 <dt><code>"text/html"</code> 2563 <dt><code>"application/xhtml+xml"</code> 2564 <dt><code>"application/vnd.wap.xhtml+xml"</code> 2565 </dl> 2566 </dd> 2567 </dl> 2568 2569 2570 <p><b>Example intent:</b></p> 2571 <pre> 2572 public void openWebPage(String url) { 2573 Uri webpage = Uri.parse(url); 2574 Intent intent = new Intent(Intent.ACTION_VIEW, webpage); 2575 if (intent.resolveActivity(getPackageManager()) != null) { 2576 startActivity(intent); 2577 } 2578 } 2579 </pre> 2580 2581 2582 <p><b>Example intent filter:</b></p> 2583 <pre> 2584 <activity ...> 2585 <intent-filter> 2586 <action android:name="android.intent.action.VIEW" /> 2587 <!-- Include the host attribute if you want your app to respond 2588 only to URLs with your app's domain. --> 2589 <data android:scheme="http" android:host="www.example.com" /> 2590 <category android:name="android.intent.category.DEFAULT" /> 2591 <!-- The BROWSABLE category is required to get links from web pages. --> 2592 <category android:name="android.intent.category.BROWSABLE" /> 2593 </intent-filter> 2594 </activity> 2595 </pre> 2596 2597 2598 <p class="note"><strong>Tip:</strong> If your Android app provides functionality similar to 2599 your web site, include an intent filter for URLs that point to your web site. Then, 2600 if users have your app installed, links from emails or other web pages pointing to your web site 2601 open your Android app instead of your web page.</p> 2602 2603 2604 2605 2606 2607 2608 2609 <h2 id="AdbIntents">Verify Intents with the Android Debug Bridge</h2> 2610 2611 <p>To verify that your app responds to the intents that you want to support, you can use the 2612 <a href="{@docRoot}tools/help/adb.html"><code>adb</code></a> tool to fire specific intents:</p> 2613 2614 <ol> 2615 <li>Set up an Android device for <a href="{@docRoot}tools/device.html#setting-up">development</a>, 2616 or use a <a href="{@docRoot}tools/devices/emulator.html#avds">virtual device</a>.</li> 2617 <li>Install a version of your app that handles the intents you want to support.</li> 2618 <li>Fire an intent using <code>adb</code>: 2619 <pre class="no-pretty-print"> 2620 adb shell am start -a <ACTION> -t <MIME_TYPE> -d <DATA> \ 2621 -e <EXTRA_NAME> <EXTRA_VALUE> -n <ACTIVITY> 2622 </pre> 2623 <p>For example:</p> 2624 <pre class="no-pretty-print"> 2625 adb shell am start -a android.intent.action.DIAL \ 2626 -d tel:555-5555 -n org.example.MyApp/.MyActivity 2627 </pre> 2628 <li>If you defined the required intent filters, your app should handle the intent.</li> 2629 </ol> 2630 2631 2632 <p>For more information, see 2633 <a href="{@docRoot}tools/help/adb.html#am">Using activity manager (am)</a>.</p> 2634 2635 2636 2637 2638 2639 2640 <h2 id="Now">Intents Fired by Google Now</h2> 2641 2642 <p><a href="http://www.google.com/landing/now/">Google Now</a> recognizes many voice commands 2643 and fires intents for them. As such, users may launch your app with a Google Now voice command 2644 if your app declares the corresponding intent filter. For example, if your app can 2645 <a href="#CreateAlarm">set an alarm</a> and you add the corresponding intent filter to your 2646 manifest file, Google Now lets users choose your app when they request to set an alarm, as 2647 shown in figure 1.</p> 2648 2649 <img src="{@docRoot}guide/components/images/google-action.png" 2650 srcset="{@docRoot}guide/components/images/google-action_2x.png 2x" 2651 width="700" height="241" alt=""/> 2652 <p class="img-caption"><strong>Figure 1.</strong> Google Now lets users choose from installed 2653 apps that support a given action.</p> 2654 2655 <p>Google Now recognizes voice commands for the actions listed in table 1. For more information 2656 about declaring each intent filter, click on the action description.</p> 2657 2658 <p class="table-caption"><strong>Table 1.</strong> Voice commands recognized by Google Now 2659 (Google Search app v3.6).</p> 2660 <table> 2661 <tr> 2662 <th>Category</th> 2663 <th>Details and Examples</th> 2664 <th>Action Name</th> 2665 </tr> 2666 <tr> 2667 <td rowspan="2" style="vertical-align:middle">Alarm</td> 2668 <td> 2669 <p><a href="#CreateAlarm">Set alarm</a></p> 2670 <ul class="now-list"> 2671 <li>"set an alarm for 7 am"</li> 2672 </ul> 2673 </td> 2674 <td>{@link android.provider.AlarmClock#ACTION_SET_ALARM AlarmClock.ACTION_SET_ALARM}</td> 2675 </tr> 2676 <tr> 2677 <td> 2678 <p><a href="#CreateTimer">Set timer</a></p> 2679 <ul class="now-list"> 2680 <li>"set a timer for 5 minutes"</li> 2681 </ul> 2682 </td> 2683 <td>{@link android.provider.AlarmClock#ACTION_SET_TIMER AlarmClock.ACTION_SET_TIMER}</td> 2684 </tr> 2685 <tr> 2686 <td style="vertical-align:middle">Communication</td> 2687 <td> 2688 <p><a href="#DialPhone">Call a number</a></p> 2689 <ul class="now-list"> 2690 <li>"call 555-5555"</li> 2691 <li>"call bob"</li> 2692 <li>"call voicemail"</li> 2693 </ul> 2694 </td> 2695 <td>{@link android.content.Intent#ACTION_CALL Intent.ACTION_CALL}</td> 2696 </tr> 2697 <tr> 2698 <td rowspan="5" style="vertical-align:middle">Fitness</td> 2699 <td> 2700 <p><a href="#TrackRide">Start/stop a bike ride</a></p> 2701 <ul class="now-list"> 2702 <li>"start cycling"</li> 2703 <li>"start my bike ride"</li> 2704 <li>"stop cycling"</li> 2705 </ul> 2706 </td> 2707 <td><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 2708 <code>FitnessIntents.ACTION_TRACK</code></a></td> 2709 </tr> 2710 <tr> 2711 <td> 2712 <p><a href="#TrackRun">Start/stop a run</a></p> 2713 <ul class="now-list"> 2714 <li>"track my run"</li> 2715 <li>"start running"</li> 2716 <li>"stop running"</li> 2717 </ul> 2718 </td> 2719 <td><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 2720 <code>FitnessIntents.ACTION_TRACK</code></a></td> 2721 </tr> 2722 <tr> 2723 <td> 2724 <p><a href="#TrackWorkout">Start/stop a workout</a></p> 2725 <ul class="now-list"> 2726 <li>"start a workout"</li> 2727 <li>"track my workout"</li> 2728 <li>"stop workout"</li> 2729 </ul> 2730 </td> 2731 <td><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_TRACK"> 2732 <code>FitnessIntents.ACTION_TRACK</code></a></code></td> 2733 </tr> 2734 <tr> 2735 <td> 2736 <p><a href="#ShowHeartRate">Show heart rate</a></p> 2737 <ul class="now-list"> 2738 <li>"what's my heart rate"</li> 2739 <li>"what's my bpm"</li> 2740 </ul> 2741 </td> 2742 <td><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_VIEW"> 2743 <code>FitnessIntents.ACTION_VIEW</code></a></code></td> 2744 </tr> 2745 <tr> 2746 <td> 2747 <p><a href="#ShowStepCount">Show step count</a></p> 2748 <ul class="now-list"> 2749 <li>"how many steps have I taken"</li> 2750 <li>"what's my step count"</li> 2751 </ul> 2752 </td> 2753 <td><a href="{@docRoot}reference/com/google/android/gms/fitness/FitnessIntents.html#ACTION_VIEW"> 2754 <code>FitnessIntents.ACTION_VIEW</code></a></td> 2755 </tr> 2756 <tr> 2757 <td style="vertical-align:middle">Local</td> 2758 <td> 2759 <p><a href="#CallCar">Book a car</a></p> 2760 <ul class="now-list"> 2761 <li>"call me a car"</li> 2762 <li>"book me a taxi"</li> 2763 </ul> 2764 </td> 2765 <td><a href="{@docRoot}reference/com/google/android/gms/actions/ReserveIntents.html#ACTION_RESERVE_TAXI_RESERVATION"> 2766 <code>ReserveIntents<br/>.ACTION_RESERVE_TAXI_RESERVATION</code></a></td> 2767 </tr> 2768 <tr> 2769 <td rowspan="3" style="vertical-align:middle">Media</td> 2770 <td> 2771 <p><a href="#PlaySearch">Play music from search</a></p> 2772 <ul class="now-list"> 2773 <li>"play michael jackson billie jean"</li> 2774 </ul> 2775 </td> 2776 <td>{@link android.provider.MediaStore#INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH MediaStore<br/>.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH}</td> 2777 </tr> 2778 <tr> 2779 <td> 2780 <p><a href="#CameraStill">Take a picture</a></p> 2781 <ul class="now-list"> 2782 <li>"take a picture"</li> 2783 </ul> 2784 </td> 2785 <td>{@link android.provider.MediaStore#INTENT_ACTION_STILL_IMAGE_CAMERA MediaStore<br/>.INTENT_ACTION_STILL_IMAGE_CAMERA}</td> 2786 </tr> 2787 <tr> 2788 <td> 2789 <p><a href="#CameraVideo">Record a video</a></p> 2790 <ul class="now-list"> 2791 <li>"record a video"</li> 2792 </ul> 2793 </td> 2794 <td>{@link android.provider.MediaStore#INTENT_ACTION_VIDEO_CAMERA MediaStore<br/>.INTENT_ACTION_VIDEO_CAMERA}</td> 2795 </tr> 2796 <tr> 2797 <td style="vertical-align:middle">Search</td> 2798 <td> 2799 <p><a href="#SearchOnApp">Search using a specific app</a></p> 2800 <ul class="now-list"> 2801 <li>"search for cat videos <br/>on myvideoapp"</li> 2802 </ul> 2803 </td> 2804 <td><code>"com.google.android.gms.actions<br/>.SEARCH_ACTION"</code></td> 2805 </tr> 2806 <tr> 2807 <td style="vertical-align:middle">Web browser</td> 2808 <td> 2809 <p><a href="#ViewUrl">Open URL</a></p> 2810 <ul class="now-list"> 2811 <li>"open example.com"</li> 2812 </ul> 2813 </td> 2814 <td>{@link android.content.Intent#ACTION_VIEW Intent.ACTION_VIEW}</td> 2815 </tr> 2816 </table> 2817