Slide 1

Slide 1 text

Building an Android Wear app

Slide 2

Slide 2 text

Anatomy of an Android Wear app 4 Wearable app 4 Mobile app, with wearable app packaged inside 4 Communicate via notifications and/or Google Play Services APIs

Slide 3

Slide 3 text

Never Gonna GIF You Up

Slide 4

Slide 4 text

Loading a random GIF on the watch 1. UI library for displaying GIFs 2. Request random GIF from Giphy API 3. Make API request, update view

Slide 5

Slide 5 text

Loading a random GIF on the watch 1. UI library for displaying GIFs 2. Request random GIF from Giphy API 3. Make API request, update view Most wearables don't have internet...yet

Slide 6

Slide 6 text

Wearable app

Slide 7

Slide 7 text

Wearable app 1. UI library for displaying GIFs 2. Request GIF from mobile app 3. Listen for data change from phone 4. Update view

Slide 8

Slide 8 text

Request GIF from mobile app Set nodes = Wearable.CapabilityApi .getCapability(googleApiClient, "gif_me", CapabilityApi.FILTER_REACHABLE) .await() .getCapability() .getNodes(); if (!nodes.isEmpty()) { for (Node node : nodes) { Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "gif/random", null).await(); } }

Slide 9

Slide 9 text

Listen for data changes @Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { DataItem item = event.getDataItem(); if (item.getUri().getPath().compareTo("/image") == 0) { Asset asset = DataMapItem.fromDataItem(item).getDataMap().get("random_gif"); // Do something with asset } } } }

Slide 10

Slide 10 text

Mobile app

Slide 11

Slide 11 text

Mobile app 1. WearableListenerService to listen for GIF requests 2. Request random GIF from Giphy API 3. Push file bytes to wearable via Data API

Slide 12

Slide 12 text

Registering a WearableListenerService - AndroidManifest.xml

Slide 13

Slide 13 text

Registering a WearableListenerService: res/values/wear.xml gif_me

Slide 14

Slide 14 text

WearableListenerService public class GifRequestWearableListenerService extends WearableListenerService { @Override public void onMessageReceived(MessageEvent messageEvent) { if (messageEvent.getPath().equals("gif/random")) { bytes[] imageBytes = getRandomGif(); Asset asset = Asset.createFromBytes(imageBytes) pushAsset(asset); } } private void pushAsset(Asset asset) { PutDataMapRequest request = PutDataMapRequest.create("/image"); request.getDataMap().putAsset("random_gif", asset); Wearable.DataApi.putDataItem(googleApiClient, request.asPutDataRequest()); } }

Slide 15

Slide 15 text

Achtung! 4 Enable developer options and debugging on the wearable 4 Packaged wearable apps aren't automatically deployed for debug builds 4 Deploy the right app to the right device 4 It's difficult to debug end-to-end. Focus on one end at a time.

Slide 16

Slide 16 text

Weird stuff 4 Retrolambda doesn't currently work with Android Wear. It seems to break the packaging of the wearable app into the mobile app.