24 9月 2015
Originally posted on the Geo Developers Blog
Posted by Ankur Kotwal, Developer Advocate
Some Android Wear apps are most useful when they are always available to the user, even at a glance. Now, with Google Play Services 8.1, the Google Maps Android API supports ambient mode, the API that provides always-on capabilities. In ambient mode, the map adjusts its style to provide a simplified, low-color rendering of the map. All markers, objects, and UI controls disappear, keeping the map on the screen while letting the user know that it is not currently ready to accept user input. An important advantage is the camera position and zoom level are retained, thus keeping the user’s context within the map.
The screenshot below show how maps appear in interactive mode and in ambient mode.
To implement ambient mode in your maps, follow these steps:
dependencies { compile 'com.google.android.support:wearable:1.2.0' provided 'com.google.android.wearable:wearable:1.0.0' }
<application> <uses-library android:name="com.google.android.wearable" android:required="false" /> ... </application>
<uses-permission android:name="android.permission.WAKE_LOCK" />
setAmbientEnabled()
method. This tells the framework that the app should enter ambient mode rather than returning to the watch face.
GoogleMapOptions.ambientEnabled(true)
. This informs the API to pre-load necessary map tiles for ambient mode.onEnterAmbient()
method in your wearable activity. Override onEnterAmbient()
and call MapFragment.onEnterAmbient()
or MapView.onEnterAmbient()
. The map changes to a non-interactive, low-color rendering of the map.
onUpdateAmbient()
. If you need more frequent updates, check out this guide.
onExitAmbient()
method in your wearable activity. Override onExitAmbient()
and call MapFragment.onExitAmbient()
or MapView.onExitAmbient()
. The map returns to the normal rendering and is now ready to accept user input.
With always-on maps on Android Wear, you can now show maps at a glance. For more information on these APIs check out the documentation and the sample code.