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
62
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
260
Multiple Developers, One App: How to Not Break Everything
abdyer
0
310
Things That Suck About Android Development
abdyer
0
520
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
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
EventSourcingの理想と現実
wenas
6
2.3k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
100
Outline View in SwiftUI
1024jp
1
320
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Adopting Sorbet at Scale
ufuk
73
9.1k
Scaling GitHub
holman
458
140k
Writing Fast Ruby
sferik
627
61k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
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.