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