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
82
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
330
Multiple Developers, One App: How to Not Break Everything
abdyer
0
360
Things That Suck About Android Development
abdyer
0
580
MCE2015 - Automated Testing for Modern Android Applications
abdyer
0
1.4k
BABBQ5 - Automated Testing for Modern Android Applications
abdyer
14
3.8k
Other Decks in Programming
See All in Programming
Cap'n Webについて
yusukebe
0
170
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
850
Patterns of Patterns
denyspoltorak
0
600
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
320
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
5.5k
これならできる!個人開発のすゝめ
tinykitten
PRO
0
150
gunshi
kazupon
1
140
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
230
ゆくKotlin くるRust
exoego
1
200
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
210
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
760
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.7k
Featured
See All Featured
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
For a Future-Friendly Web
brad_frost
180
10k
The Cult of Friendly URLs
andyhume
79
6.8k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Paper Plane
katiecoart
PRO
0
45k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Ethics towards AI in product and experience design
skipperchong
1
170
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
1
36
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
65
35k
Building an army of robots
kneath
306
46k
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.