SlideShare 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!
The dirty secret of 
Card UIs: 
it’s 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, doesn’t have Internet 
• The phone? No, would kill battery 
• App Engine? No, can’t 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 
• Don’t 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

More Related Content

Viewers also liked (9)

Frida kalo
Frida kaloFrida kalo
Frida kalo
 
Arma tu plan de acción
Arma tu plan de acciónArma tu plan de acción
Arma tu plan de acción
 
Official Housing Management - 2015
Official Housing Management - 2015Official Housing Management - 2015
Official Housing Management - 2015
 
Daksh engineers
Daksh engineersDaksh engineers
Daksh engineers
 
Ejercicios de matematica adelmary
Ejercicios de matematica adelmaryEjercicios de matematica adelmary
Ejercicios de matematica adelmary
 
English 2.0
English 2.0English 2.0
English 2.0
 
303 pwetp
303 pwetp303 pwetp
303 pwetp
 
Color
ColorColor
Color
 
Volunteer Orientation
Volunteer OrientationVolunteer Orientation
Volunteer Orientation
 

Similar to Developing for android wear

GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...mharkus
 
Android Wearables ii
Android Wearables iiAndroid Wearables ii
Android Wearables iiKetan Raval
 
Android Wear – IO Extended
Android Wear – IO ExtendedAndroid Wear – IO Extended
Android Wear – IO ExtendedDouglas Drumond
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android WearPeter Friese
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android WearPeter Friese
 
Android Evolution, AppForum 2014, Brussels, Friedger Müffke
Android Evolution, AppForum 2014, Brussels, Friedger MüffkeAndroid Evolution, AppForum 2014, Brussels, Friedger Müffke
Android Evolution, AppForum 2014, Brussels, Friedger MüffkeFriedger Müffke
 
Exercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callExercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callmaamir farooq
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification TutorialKetan Raval
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloudfirenze-gtug
 
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
"It's Time" - Android Wear codelab - GDG MeetsU - L'AquilaGiuseppe Cerratti
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Alfredo Morresi
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...naseeb20
 
Getting Ready For Android Wear
Getting Ready For Android WearGetting Ready For Android Wear
Getting Ready For Android WearRaveesh Bhalla
 
android level 3
android level 3android level 3
android level 3DevMix
 
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on AndroidMobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on AndroidAlberto Ruibal
 

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...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
 
Android Wearables ii
Android Wearables iiAndroid Wearables ii
Android Wearables ii
 
Android Wear – IO Extended
Android Wear – IO ExtendedAndroid Wear – IO Extended
Android Wear – IO Extended
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 
Android Wear Development
Android Wear DevelopmentAndroid Wear Development
Android Wear Development
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 
Android Evolution, AppForum 2014, Brussels, Friedger Müffke
Android Evolution, AppForum 2014, Brussels, Friedger MüffkeAndroid Evolution, AppForum 2014, Brussels, Friedger Müffke
Android Evolution, AppForum 2014, Brussels, Friedger Müffke
 
Android For All The Things
Android For All The ThingsAndroid For All The Things
Android For All The Things
 
Exercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callExercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone call
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification Tutorial
 
Android wear (coding)
Android wear (coding)Android wear (coding)
Android wear (coding)
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloud
 
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...
 
Notification android
Notification androidNotification android
Notification android
 
Getting Ready For Android Wear
Getting Ready For Android WearGetting Ready For Android Wear
Getting Ready For Android Wear
 
DAY2.pptx
DAY2.pptxDAY2.pptx
DAY2.pptx
 
android level 3
android level 3android level 3
android level 3
 
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on AndroidMobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
 

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!
  • 4.
  • 5. The dirty secret of Card UIs: it’s 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, doesn’t have Internet • The phone? No, would kill battery • App Engine? No, can’t 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 • Don’t 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