In this session, I will give an overview of Android Wear and how to integrate it in your product strategy. We will look at the underlying design principles and discuss a number of use cases for apps that connect to wearable devices. After that, we will take a look at some code examples and learn how to use the Android Wear SDK.
17. BigPictureStyle
sendNotification()
Intent viewIntent = new Intent(context, DummyActivity.class);
PendingIntent viewPendingIntent = PendingIntent.getActivity(context, 0, viewIntent, 0);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setSmallIcon(R.drawable.plane)
.setContentTitle(String.format("Flight AW123 is ready to board", notificationId))
.setContentText("Please proceed to gate C 17 to board. Have a nice flight!")
.setStyle(
new NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(context.getResources(),
R.drawable.sanfrancisco))
.setBigContentTitle("Flight AW123 is ready to board.")
.setSummaryText("Please proceed to gate C 17 to board. Have a nice flight!"))
.setContentIntent(viewPendingIntent)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId++, notification);
21. Adding Pages to Notifications
sendNotification()
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setSmallIcon(R.drawable.plane)
.setContentTitle(String.format("Flight AW123 is ready to board", notificationId))
.setContentText("Please proceed to gate C 17 to board. Have a nice flight!")
.setContentIntent(viewPendingIntent)
.extend(new NotificationCompat.WearableExtender()
.addPages(pages))
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId++, notification);
24. Sending a Voice Input Notification
sendNotification()
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setSmallIcon(R.drawable.plane)
.setContentTitle(String.format("Flight AW123 is ready to board", notificationId))
.setContentText("Please proceed to gate C 17 to board. Have a nice flight!")
.extend(new NotificationCompat.WearableExtender()
.addPages(pages)
.addAction(replyAction))
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId++, notification);
42. Transferring Assets
sendDataToWearable()
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream);
Asset asset = Asset.createFromBytes(byteStream.toByteArray());
PutDataMapRequest dataMap =
PutDataMapRequest.create(Constants.FLIGHT_PATH + "/" + Uri.encode("SFO"));
dataMap.getDataMap().putString(Constants.EXTRA_FLIGHTNUMBER, "AC123");
dataMap.getDataMap().putString(Constants.EXTRA_GATE, "C 17");
dataMap.getDataMap().putAsset(Constants.EXTRA_DESTINATION, imageAssetDestination);
PutDataRequest request = dataMap.asPutDataRequest();
// Send the data over
DataApi.DataItemResult result =
Wearable.DataApi.putDataItem(googleApiClient, request).await();
43. Sending Messages
sendDataToWearable()
// If successful store the data path
// Construct an array of all successfully sent data paths
DataMap itemPathMap = new DataMap();
itemPathMap.putString(Constants.EXTRA_UPDATED_FLIGHTS,
result.getDataItem().getUri().toString());
// Convert to bytes to be send with the message
byte[] dataMapBytes = itemPathMap.toByteArray();
44. Sending Messages
sendDataToWearable()
// If successful store the data path
// Construct an array of all successfully sent data paths
DataMap itemPathMap = new DataMap();
itemPathMap.putString(Constants.EXTRA_UPDATED_FLIGHTS,
result.getDataItem().getUri().toString());
// Convert to bytes to be send with the message
byte[] dataMapBytes = itemPathMap.toByteArray();
Iterator<String> itr = Utilities.getNodes(googleApiClient).iterator();
while (itr.hasNext()) {
// Notify all nodes to "start", providing the data paths of all
// transmitted tourist attractions. What "start" does will be up
// to the wearable.
!
}
45. Sending Messages
sendDataToWearable()
// If successful store the data path
// Construct an array of all successfully sent data paths
DataMap itemPathMap = new DataMap();
itemPathMap.putString(Constants.EXTRA_UPDATED_FLIGHTS,
result.getDataItem().getUri().toString());
// Convert to bytes to be send with the message
byte[] dataMapBytes = itemPathMap.toByteArray();
Iterator<String> itr = Utilities.getNodes(googleApiClient).iterator();
while (itr.hasNext()) {
// Notify all nodes to "start", providing the data paths of all
// transmitted tourist attractions. What "start" does will be up
// to the wearable.
Wearable.MessageApi.sendMessage(googleApiClient, itr.next(),
Constants.START_PATH, dataMapBytes);
}