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
59
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
240
Multiple Developers, One App: How to Not Break Everything
abdyer
0
300
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
ここ1~2年くらいで 使えるようになった(主要ブラウザーの最新版 がすべて対応した ) ウェブの新機能について ランダムに喋る!
myzkyy
9
6.5k
incrementalモデルの理解を深める
ikkimiyazaki
2
640
【KMC春合宿2024】実装視点で見るNeural Radiance Fields
runningoutrate
0
150
TDDと今まで
kanayannet
0
140
htmx is fun!
codehex
2
190
RubyVM を PHP で実装する 〜Hello World を出力するまで〜
memory1994
PRO
1
490
自動テスト実行結果の目的を整理する / Organizing objectives of automated test results
twada
PRO
10
2.1k
DDD, necessary but insufficient: physical design principles for microservices
cer
PRO
0
2.2k
TCAの Shared Stateって どういう仕組みになってんの?
yimajo
0
330
品質とスピードを両立: TypeScriptの柔軟な型システムをバックエンドで活用する
kosui
4
920
Learning PHP and Static Analysis with PHP Parser
inouehi
1
250
プロンプトエンジニアリング入門
tomokusaba
2
980
Featured
See All Featured
Teambox: Starting and Learning
jrom
126
8.4k
Atom: Resistance is Futile
akmur
258
25k
Learning to Love Humans: Emotional Interface Design
aarron
266
39k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
19
1.9k
Keith and Marios Guide to Fast Websites
keithpitt
407
22k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
153
14k
The Invisible Customer
myddelton
114
12k
Automating Front-end Workflow
addyosmani
1353
200k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
225
51k
Designing on Purpose - Digital PM Summit 2013
jponch
109
6.4k
KATA
mclloyd
14
11k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
950
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.