際際滷

際際滷Share a Scribd company logo
Developing for 
Android Wear 
Thomas Oldervoll 
thomas@zenior.no
Before we begin 
Have you created an Android app? 
Is it your day job? 
Do you own a Android Wear device?
Android Wear are small and quick to implement - 
the ideal side project!
Developing for android wear
The dirty secret of 
Card UIs: 
its just notifications
Demo: 
Going from plain-old 
notification to Wear card
Plain old notification 
NotificationCompat.Builder notificationBuilder = 
new NotificationCompat.Builder(context) 
.setSmallIcon(R.drawable.sunrise32) 
.setContentTitle(story.title) 
.setContentText(story.contents) 
.setContentIntent(createReadMoreIntent(story)) 
.setAutoCancel(true); 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(context); 
notificationManager.notify(0, notificationBuilder.build());
Add an image and it looks like a card 
NotificationCompat.Builder notificationBuilder = 
new NotificationCompat.Builder(context) 
.setSmallIcon(R.drawable.sunrise32) 
.setContentTitle(story.title) 
.setContentText(story.contents) 
.setContentIntent(createReadMoreIntent(story)) 
.setAutoCancel(true); 
Bitmap image = loadImage(story.image); 
if (image != null) { 
notificationBuilder.setLargeIcon(image); 
} 
NotificationManagerCompat notificationManager = 
NotificationManagerCompat.from(context); 
notificationManager.notify(0, notificationBuilder.build());
Add pages 
NotificationCompat.WearableExtender wearableExtender = 
new NotificationCompat.WearableExtender(); 
for (Story subStory : story.subStories) { 
Notification storyPageNotification = 
new NotificationCompat.Builder(context) 
.setContentTitle(bold(subStory.title)) 
.setContentText(subStory.contents) 
.build(); 
wearableExtender.addPage(storyPageNotification); 
} 
notificationBuilder.extend(wearableExtender);
Add a separate page for just the image 
if (image != null) { 
Notification imageOnlyNotification = 
new NotificationCompat.Builder(context) 
.extend(new NotificationCompat.WearableExtender() 
.setBackground(image) 
.setHintShowBackgroundOnly(true)) 
.build(); 
wearableExtender.addPage(imageOnlyNotification); 
}
Show more content in the phone 
notification 
NotificationCompat.BigTextStyle style = 
new NotificationCompat.BigTextStyle(); 
style.bigText(story.contents); 
NotificationCompat.Builder notificationBuilder = 
new NotificationCompat.Builder(context) 
.setSmallIcon(R.drawable.sunrise32) 
.setContentTitle(story.title) 
.setContentText(story.contents) 
.setContentIntent(createReadMoreIntent(story)) 
.setAutoCancel(true) 
.setStyle(style);
News alert app 
 Push news alerts as they happen 
 By default push most important stories 
 Allow user to subscribe to stories of interest
Who detects when 
something happened? 
 The watch? No, doesnt have Internet 
 The phone? No, would kill battery 
 App Engine? No, cant use Web Sockets 
 Google Cloud Mananged VMs? Yes.
Demo: 
News alerts
Adding actions 
notificationBuilder.addAction( 
createFollowAction(story.channel, notificationId)); 
pr private NotificationCompat.Action createFollowAction( 
String channel, int notifcationId) { 
int icon = R.drawable.ic_action_important; 
String title = context.getString(R.string.unfollow); 
String action = FetcherService.ACTION_UNFOLLOW; 
Intent intent = new Intent(context, FetcherService.class); 
intent.setAction(action + "/" + channel + "/" + notifcationId); 
PendingIntent pi = PendingIntent.getService(context, 0, intent, 0); 
return new NotificationCompat.Action(icon, title, pi); 
}
When do you need more 
than notifications? 
 More advanced UIs? Can send custom activities in 
notifications 
 Launch from Wear 
 Use Wear sensor 
 Run with no phone connection
What can Wear apps do? 
 Pretty much anything an Android app can do - but 
keep the form factor in mind 
 No Internet, no webkit 
 APIs for sending and receiving messages and data 
to/from phone
Demo: 
Browsing with a 
Wear app
Sending messages 
from watch to phone 
GoogleApiClient apiClient = new GoogleApiClient.Builder(context) 
.addApi(Wearable.API) 
.build(); 
apiClient.blockingConnect(); 
for (String nodeId : getRemoteNodes(apiClient)) { 
Wearable.MessageApi.sendMessage(apiClient, nodeId, "/fetch", null); 
} 
private Collection<String> getRemoteNodes(GoogleApiClient apiClient) { 
HashSet <String>results = new HashSet<String>(); 
NodeApi.GetConnectedNodesResult nodes = 
Wearable.NodeApi.getConnectedNodes(apiClient).await(); 
for (Node node : nodes.getNodes()) { 
results.add(node.getId()); 
} 
return results; 
}
Receiving messages on phone 
public class FetcherService extends Service 
implements MessageApi.MessageListener { 
@Override 
public void onMessageReceived(MessageEvent messageEvent) { 
Log.i(TAG, "Received " + messageEvent); 
if (/fetch.equals(messageEvent.getPath())) { 
String wearNodeId = messageEvent.getSourceNodeId(); 
new StoryFetcher().execute(wearNodeId); 
} 
} 
 
}
Connecting to watch from phone 
private GoogleApiClient createApiClient() { 
return new GoogleApiClient.Builder(this) 
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { 
@Override 
public void onConnected(Bundle connectionHint) { 
Log.d(TAG, "onConnected: " + connectionHint); 
Wearable.MessageApi.addListener(apiClient, FetcherService.this); 
} 
@Override 
public void onConnectionSuspended(int cause) { 
Log.d(TAG, "onConnectionSuspended: " + cause); 
} 
}) 
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { 
@Override 
public void onConnectionFailed(ConnectionResult result) { 
Log.d(TAG, "onConnectionFailed: " + result); 
} 
}) 
.addApi(Wearable.API) 
.build(); 
}
Wear-enabling your app 
 Dont squeeze the phone UI onto the wrist! 
 Instead, enrich your notifications. This will make 
your app better on the phone as well. 
 Use your app on a watch every day
Ad

Recommended

Session #8 adding magic to your app
Session #8 adding magic to your app
Vitali Pekelis
Introduction to Android Wear
Introduction to Android Wear
gabrielemariotti
How Profitable is the Hotel Industry? National Hotels Association
How Profitable is the Hotel Industry? National Hotels Association
National Hotels Association, Inc
ActionIntel Detailed Overview - Emerging Strategies
ActionIntel Detailed Overview - Emerging Strategies
leadcrafting
Els materials
Els materials
sonia242001
Self Esteem
Self Esteem
Praveen Jalaraddi
Plate Loaded Fitness Equipment - Sai Works
Plate Loaded Fitness Equipment - Sai Works
Deep Kevadia
亠舒仍仆亳 仂弍仍亳亳 仆亠亠舒仍仆亳仄 仂亟仆仂亳仄舒
亠舒仍仆亳 仂弍仍亳亳 仆亠亠舒仍仆亳仄 仂亟仆仂亳仄舒
Marijana Stavljanin
Frida kalo
Frida kalo
Marijana Stavljanin
Arma tu plan de acci坦n
valentinaaaaaaaaaa
Official Housing Management - 2015
Official Housing Management - 2015
National Hotels Association, Inc
Daksh engineers
Daksh engineers
Daksh Engineers
Ejercicios de matematica adelmary
Ejercicios de matematica adelmary
AdelmaryM
English 2.0
English 2.0
Agust鱈n Duarte
303 pwetp
303 pwetp
lol lol91
Color
Color
Andrew_Cox
Volunteer Orientation
Volunteer Orientation
James Donell
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
mharkus
Developing For Android Wear - Part 2
Developing For Android Wear - Part 2
Justin Munger
Android Wear: A Developer's Perspective
Android Wear: A Developer's Perspective
Vin Lim
Android wearpp
Android wearpp
Paul Trebilcox-Ruiz
Android Wear from zero to hero
Android Wear from zero to hero
Roberto Orgiu
Break Timer: Android-wear introduction and application case-study
Break Timer: Android-wear introduction and application case-study
Umair Vatao
See Androids Fighting: Connect Salesforce with Your Android Wear Watch
See Androids Fighting: Connect Salesforce with Your Android Wear Watch
Salesforce Developers
Android Wearable App
Android Wearable App
Mindfire Solutions
Getting Ready For Android Wear
Getting Ready For Android Wear
Raveesh Bhalla
Android On Your Sleeve - DroidCon Montreal 2015
Android On Your Sleeve - DroidCon Montreal 2015
Neal Sanche
Developing for Android Wear - Part 1
Developing for Android Wear - Part 1
Justin Munger
Android Wear Presentation
Android Wear Presentation
Zi Yong Chua
Android Wear, a developer's perspective
Android Wear, a developer's perspective
Sebastian Vieira

More Related Content

Viewers also liked (9)

Frida kalo
Frida kalo
Marijana Stavljanin
Arma tu plan de acci坦n
valentinaaaaaaaaaa
Official Housing Management - 2015
Official Housing Management - 2015
National Hotels Association, Inc
Daksh engineers
Daksh engineers
Daksh Engineers
Ejercicios de matematica adelmary
Ejercicios de matematica adelmary
AdelmaryM
English 2.0
English 2.0
Agust鱈n Duarte
303 pwetp
303 pwetp
lol lol91
Color
Color
Andrew_Cox
Volunteer Orientation
Volunteer Orientation
James Donell
Arma tu plan de acci坦n
valentinaaaaaaaaaa
Ejercicios de matematica adelmary
Ejercicios de matematica adelmary
AdelmaryM
303 pwetp
303 pwetp
lol lol91
Volunteer Orientation
Volunteer Orientation
James Donell

Similar to Developing for android wear (20)

GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
mharkus
Developing For Android Wear - Part 2
Developing For Android Wear - Part 2
Justin Munger
Android Wear: A Developer's Perspective
Android Wear: A Developer's Perspective
Vin Lim
Android wearpp
Android wearpp
Paul Trebilcox-Ruiz
Android Wear from zero to hero
Android Wear from zero to hero
Roberto Orgiu
Break Timer: Android-wear introduction and application case-study
Break Timer: Android-wear introduction and application case-study
Umair Vatao
See Androids Fighting: Connect Salesforce with Your Android Wear Watch
See Androids Fighting: Connect Salesforce with Your Android Wear Watch
Salesforce Developers
Android Wearable App
Android Wearable App
Mindfire Solutions
Getting Ready For Android Wear
Getting Ready For Android Wear
Raveesh Bhalla
Android On Your Sleeve - DroidCon Montreal 2015
Android On Your Sleeve - DroidCon Montreal 2015
Neal Sanche
Developing for Android Wear - Part 1
Developing for Android Wear - Part 1
Justin Munger
Android Wear Presentation
Android Wear Presentation
Zi Yong Chua
Android Wear, a developer's perspective
Android Wear, a developer's perspective
Sebastian Vieira
Android Wear Development
Android Wear Development
Takahiro (Poly) Horikawa
Android wear SDK introduction
Android wear SDK introduction
Tiziano Basile
Droidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introduction
Michelantonio Trizio
Wearables meetup
Wearables meetup
Perfecto Mobile
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
Giuseppe Cerratti
8尊 Betabeers Granada: Android Wear por GDG Granada
8尊 Betabeers Granada: Android Wear por GDG Granada
JM Robles
Developing Your First Android Wear App
Developing Your First Android Wear App
James Montemagno
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
mharkus
Developing For Android Wear - Part 2
Developing For Android Wear - Part 2
Justin Munger
Android Wear: A Developer's Perspective
Android Wear: A Developer's Perspective
Vin Lim
Android Wear from zero to hero
Android Wear from zero to hero
Roberto Orgiu
Break Timer: Android-wear introduction and application case-study
Break Timer: Android-wear introduction and application case-study
Umair Vatao
See Androids Fighting: Connect Salesforce with Your Android Wear Watch
See Androids Fighting: Connect Salesforce with Your Android Wear Watch
Salesforce Developers
Getting Ready For Android Wear
Getting Ready For Android Wear
Raveesh Bhalla
Android On Your Sleeve - DroidCon Montreal 2015
Android On Your Sleeve - DroidCon Montreal 2015
Neal Sanche
Developing for Android Wear - Part 1
Developing for Android Wear - Part 1
Justin Munger
Android Wear Presentation
Android Wear Presentation
Zi Yong Chua
Android Wear, a developer's perspective
Android Wear, a developer's perspective
Sebastian Vieira
Android wear SDK introduction
Android wear SDK introduction
Tiziano Basile
Droidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introduction
Michelantonio Trizio
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
Giuseppe Cerratti
8尊 Betabeers Granada: Android Wear por GDG Granada
8尊 Betabeers Granada: Android Wear por GDG Granada
JM Robles
Developing Your First Android Wear App
Developing Your First Android Wear App
James Montemagno
Ad

Developing for android wear

  • 1. Developing for Android Wear Thomas Oldervoll thomas@zenior.no
  • 2. Before we begin Have you created an Android app? Is it your day job? Do you own a Android Wear device?
  • 3. Android Wear are small and quick to implement - the ideal side project!
  • 5. The dirty secret of Card UIs: its just notifications
  • 6. Demo: Going from plain-old notification to Wear card
  • 7. Plain old notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.sunrise32) .setContentTitle(story.title) .setContentText(story.contents) .setContentIntent(createReadMoreIntent(story)) .setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(0, notificationBuilder.build());
  • 8. Add an image and it looks like a card NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.sunrise32) .setContentTitle(story.title) .setContentText(story.contents) .setContentIntent(createReadMoreIntent(story)) .setAutoCancel(true); Bitmap image = loadImage(story.image); if (image != null) { notificationBuilder.setLargeIcon(image); } NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(0, notificationBuilder.build());
  • 9. Add pages NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); for (Story subStory : story.subStories) { Notification storyPageNotification = new NotificationCompat.Builder(context) .setContentTitle(bold(subStory.title)) .setContentText(subStory.contents) .build(); wearableExtender.addPage(storyPageNotification); } notificationBuilder.extend(wearableExtender);
  • 10. Add a separate page for just the image if (image != null) { Notification imageOnlyNotification = new NotificationCompat.Builder(context) .extend(new NotificationCompat.WearableExtender() .setBackground(image) .setHintShowBackgroundOnly(true)) .build(); wearableExtender.addPage(imageOnlyNotification); }
  • 11. Show more content in the phone notification NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(); style.bigText(story.contents); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.sunrise32) .setContentTitle(story.title) .setContentText(story.contents) .setContentIntent(createReadMoreIntent(story)) .setAutoCancel(true) .setStyle(style);
  • 12. News alert app Push news alerts as they happen By default push most important stories Allow user to subscribe to stories of interest
  • 13. Who detects when something happened? The watch? No, doesnt have Internet The phone? No, would kill battery App Engine? No, cant use Web Sockets Google Cloud Mananged VMs? Yes.
  • 15. Adding actions notificationBuilder.addAction( createFollowAction(story.channel, notificationId)); pr private NotificationCompat.Action createFollowAction( String channel, int notifcationId) { int icon = R.drawable.ic_action_important; String title = context.getString(R.string.unfollow); String action = FetcherService.ACTION_UNFOLLOW; Intent intent = new Intent(context, FetcherService.class); intent.setAction(action + "/" + channel + "/" + notifcationId); PendingIntent pi = PendingIntent.getService(context, 0, intent, 0); return new NotificationCompat.Action(icon, title, pi); }
  • 16. When do you need more than notifications? More advanced UIs? Can send custom activities in notifications Launch from Wear Use Wear sensor Run with no phone connection
  • 17. What can Wear apps do? Pretty much anything an Android app can do - but keep the form factor in mind No Internet, no webkit APIs for sending and receiving messages and data to/from phone
  • 18. Demo: Browsing with a Wear app
  • 19. Sending messages from watch to phone GoogleApiClient apiClient = new GoogleApiClient.Builder(context) .addApi(Wearable.API) .build(); apiClient.blockingConnect(); for (String nodeId : getRemoteNodes(apiClient)) { Wearable.MessageApi.sendMessage(apiClient, nodeId, "/fetch", null); } private Collection<String> getRemoteNodes(GoogleApiClient apiClient) { HashSet <String>results = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(apiClient).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }
  • 20. Receiving messages on phone public class FetcherService extends Service implements MessageApi.MessageListener { @Override public void onMessageReceived(MessageEvent messageEvent) { Log.i(TAG, "Received " + messageEvent); if (/fetch.equals(messageEvent.getPath())) { String wearNodeId = messageEvent.getSourceNodeId(); new StoryFetcher().execute(wearNodeId); } } }
  • 21. Connecting to watch from phone private GoogleApiClient createApiClient() { return new GoogleApiClient.Builder(this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { Log.d(TAG, "onConnected: " + connectionHint); Wearable.MessageApi.addListener(apiClient, FetcherService.this); } @Override public void onConnectionSuspended(int cause) { Log.d(TAG, "onConnectionSuspended: " + cause); } }) .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { Log.d(TAG, "onConnectionFailed: " + result); } }) .addApi(Wearable.API) .build(); }
  • 22. Wear-enabling your app Dont squeeze the phone UI onto the wrist! Instead, enrich your notifications. This will make your app better on the phone as well. Use your app on a watch every day