本节讲intent实现打车的功能,以及调用地图,以及播放媒体文件。
Local Actions
Call a carTo call a taxi, use the ACTION_RESERVE_TAXI_RESERVATION action.
Note: Apps must ask for confirmation from the user before completing the action.
Action
ACTION_RESERVE_TAXI_RESERVATION
Data URI
None
MIME Type
None
Extras
None
Example intent:
public void callCar() {
Intent intent = new Intent(ReserveIntents.ACTION_RESERVE_TAXI_RESERVATION);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
<activity ...>
<intent-filter>
<action android:name="com.google.android.gms.actions.RESERVE_TAXI_RESERVATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Maps
Show a location on a map
To open a map, use the ACTION_VIEW action and specify the location information in the intent data with one of the schemes defined below.
Action
ACTION_VIEW
Data URI Scheme
geo:latitude,longitude
Show the map at the given longitude and latitude.
Example: "geo:47.6,-122.3"
geo:latitude,longitude?z=zoom
Show the map at the given longitude and latitude at a certain zoom level. A zoom level of 1 shows the whole Earth, centered at the given lat,lng. The highest (closest) zoom level is 23.
Example: "geo:47.6,-122.3?z=11"
geo:0,0?q=lat,lng(label)
Show the map at the given longitude and latitude with a string label.
Example: "geo:0,0?q=34.99,-106.61(Treasure)"
geo:0,0?q=my+street+address
Show the location for "my street address" (may be a specific address or location query).
Example: "geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA"
Note: All strings passed in the geo URI must be encoded. For example, the string 1st & Pike, Seattle should become 1st%20%26%20Pike%2C%20Seattle. Spaces in the string can be encoded with %20 or replaced with the plus sign (+).
MIME Type
None
Example intent:
public void showMap(Uri geoLocation) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Example intent filter:
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="geo" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Play a media file
To play a music file, use the ACTION_VIEW action and specify the URI location of the file in the intent data.
Action
ACTION_VIEW
Data URI Scheme
file:<URI>
content:<URI>
http:<URL>
MIME Type
"audio/*"
"application/ogg"
"application/x-ogg"
"application/itunes"
Or any other that your app may require.
Example intent:
public void playMedia(Uri file) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(file);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Example intent filter:
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:type="audio/*" />
<data android:type="application/ogg" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>