Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building an Android Wear app
Search
Andy Dyer
August 12, 2015
Programming
0
61
Building an Android Wear app
A brief talk about building an Android Wear app presented at one of our weekly tech talks.
Andy Dyer
August 12, 2015
Tweet
Share
More Decks by Andy Dyer
See All by Andy Dyer
AppCraft: Faster Than a Speeding Release Train
abdyer
1
250
Multiple Developers, One App: How to Not Break Everything
abdyer
0
310
Things That Suck About Android Development
abdyer
0
510
MCE2015 - Automated Testing for Modern Android Applications
abdyer
0
1.3k
BABBQ5 - Automated Testing for Modern Android Applications
abdyer
14
3.7k
Other Decks in Programming
See All in Programming
Composing an API the *right* way (Droidcon Berlin 2024)
zsmb
1
450
はしめてのプログラミングとロボット制御
watawatavoltage
0
290
Temporalを取り巻く仕様を整理する
sajikix
0
120
小さな開発会社を作った理由
polidog
0
1.9k
SRE チーム立ち上げ前に考えたこと・取り組んだこと / Considerations and Preparations Before Establishing an SRE Team
mackey0225
3
320
Namespace on read
tagomoris
2
370
20240706_CDKConf
takuyay0ne
0
1.2k
Introduction of Happy Eyeballs Version 2 (RFC8305) to the Socket library
coe401_
1
220
APIのない大学ログインWebサービスをWKWebViewとJavaScriptでアプリ化した話
akidon0000
1
330
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
CSC307 Lecture 07
javiergs
PRO
0
220
【Go言語】golangci-lintの使い方
tomo1227
0
280
Featured
See All Featured
Building an army of robots
kneath
301
42k
Navigating Team Friction
lara
181
13k
GitHub's CSS Performance
jonrohan
1026
450k
Gamification - CAS2011
davidbonilla
78
4.9k
Music & Morning Musume
bryan
43
5.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
277
13k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
20
7.2k
Become a Pro
speakerdeck
PRO
15
4.8k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Statistics for Hackers
jakevdp
792
220k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
662
120k
Optimizing for Happiness
mojombo
373
69k
Transcript
Building an Android Wear app
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
Never Gonna GIF You Up
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
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
Wearable app
Wearable app 1. UI library for displaying GIFs 2. Request
GIF from mobile app 3. Listen for data change from phone 4. Update view
Request GIF from mobile app Set<Node> 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(); } }
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 } } } }
Mobile app
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
Registering a WearableListenerService - AndroidManifest.xml <service android:name=".GifRequestWearableListenerService" tools:ignore="ExportedService" > <intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> </intent-filter> </service>
Registering a WearableListenerService: res/values/wear.xml <resources> <string-array name="android_wear_capabilities"> <item>gif_me</item> </string-array> </resources>
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()); } }
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.
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.