
CHAPTER 8
Wearable GPS
By Michael Hahn, March 2015
Wearables are great when you are on the go, especially when you are out for a run or looking for destination. It would
be great to just glance at your watch for your current location, rather than pulling out your handheld. Now that some
wearables have a built-in GPS sensor, you can continue to use location-based apps even when the wearable is not
paired with a handheld.
You implement location services in a wearable using the Google Play Fused Location Provider, just as you would
in a handheld. The Android operating system takes care of choosing the GPS sensor (wearable or handheld) and
implements any necessary communications between devices. The handheld GPS is preferred when both devices have
a GPS sensor, and the switchover between sensors is automatic when pairing status changes.
You can create your first location-aware wearable app without writing a single line of handheld code. You don’t even
need to implement a handheld Activity. The section shows how.
8.1 First Wearable GPS
If you have not already done so, Create a Project . The new project wizard in Android Studio beta creates a project
with two main activities, one for the handheld device and another for the wearable. These two activities use the same
package name, which is essential for the wearable GPS to work.
8.1.1 Add Permissions and Metadata for Google Play Services
Modify the wearable manifest file to permit location service access and define Google Play Services metadata. This
example gives access permission for course location only.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application>
...
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
Add Build Dependencies
Add the following build dependencies to the wearable build.gradle file (Module:wear) in the Gradle Scripts folder, if
necessary.
37
Comentarios a estos manuales