Google Play services 7.3 started rolling out to Android devices a little less than 2 weeks ago, making some small, but much needed changes in the process. It turns out that wasn't the only purpose for that release, as it also brings some cool new capabilities developers can use in their apps. Now that the rollout is finished, Google has released an updated Play Services SDK with new capabilities for Android Wear, Google Fit, and Location Services. There's also an improvement to the GoogleApiClient class to handle situations when APIs aren't available on a given device.
Magnus is back!
We learned last week from an update to the Android Wear app that support for connecting multiple watches – and possibly other devices – had become reality. Since developers may need to communicate with multiple devices of different types, Google introduced the Capability API, which offers a simple way to communicate only with devices that offer certain features. This means it'll be easy to send messages to just devices with a screen, with Internet access, or the ability to transcribe voices.
The other big new addition is the Channel API, a system for moving large files or streaming data between two wearable devices at high speed. This operates at a lower level than DataApi and MessageApi, so developers can move information much more quickly, but without automatic syncing and distributed messaging.
Google Fit has grown up a bit since it was first introduced late last year. For most of its life, the app and API have been focused almost entirely on tracking exercise and weight changes. Play services 7.0 expanded the selection of data types to track body fat percentage and sleep activity. In the latest release, the selection grows even further to encompass an assortment of nutritional factors to make it easy to record dietary habits. Apps will be able to record details like protein, fat, cholesterol, sodium, and more.
There is also a handy new method for quickly accessing data in the present. When an app wants to show off the current totals for the day, it can call readDailyTotal and ask for a single data point like how many calories have been consumed or expended. With the exception of the step counter, all of this data still requires authentication from users before an application can read it. The step counter, however, has been made available without restriction so that developers can incorporate it into watch faces and widgets without pestering users.
We all know location has become one of the most important pieces of data available to the apps on our phones. It seems like half of the top apps want to know what city we're in, and plenty of them aren't content without pinpointing exact coordinates. However, regularly processing location data can drain the battery quickly. To give developers a little bit of a hand with optimizing their apps, Google added a new method that allows developers to receive multiple updates as a batch for more efficient processing.
There is also a new LocationCallback class that can handle both location updates and changes to LocationAvailability, which indicates there has been a change to settings and may affect the quality of incoming data.
With so many additions to Play Services, particularly for Android Wear, some of the APIs aren't available across all devices. Apps can now call addApiIfAvailable() to build up a list of services that may or may not work on all platforms. To determine the availability of each API, simply check getConnectionResult(). This should make it a little less daunting to build apps that work across multiple platforms like Wear, Auto, and TV.
Sample code and training documentation has been updated to cover most of these changes. The updated SDK is available and ready to download through the Android SDK Manager.
Also, stay tuned for a teardown, coming shortly.
- Android Developers Blog