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
67
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
310
Multiple Developers, One App: How to Not Break Everything
abdyer
0
340
Things That Suck About Android Development
abdyer
0
560
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
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
エンジニア向け採用ピッチ資料
inusan
0
160
Bytecode Manipulation 으로 생산성 높이기
bigstark
2
370
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
130
XSLTで作るBrainfuck処理系
makki_d
0
210
Is Xcode slowly dying out in 2025?
uetyo
1
190
5つのアンチパターンから学ぶLT設計
narihara
1
110
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
2
250
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
190
A2A プロトコルを試してみる
azukiazusa1
2
1.1k
Julia という言語について (FP in Julia « SIDE: F ») for 関数型まつり2025
antimon2
3
980
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
Facilitating Awesome Meetings
lara
54
6.4k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Speed Design
sergeychernyshev
32
1k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
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.