android developer tiny share-20160824

本节讲intent实现打车的功能,以及调用地图,以及播放媒体文件。

Local Actions

Call a car
 
To call a taxi, use the ACTION_RESERVE_TAXI_RESERVATION action.

Note: Apps must ask for confirmation from the user before completing the action.

Action
    ACTION_RESERVE_TAXI_RESERVATION
Data URI
    None
MIME Type
    None
Extras
    None

Example intent:

public void callCar() {
    Intent intent = new Intent(ReserveIntents.ACTION_RESERVE_TAXI_RESERVATION);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}


Example intent filter:

<activity ...>
    <intent-filter>
        <action android:name="com.google.android.gms.actions.RESERVE_TAXI_RESERVATION" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>


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>


Music or Video
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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值