Android wear

Lately I was playing with android wear so maybe I will create more posts about it but today I would like to write quick post about problem I encountered. I wanted to customize application, to show messages from application (text, image or both). The idea behind smart watches is to get notifications from your android phone to your watch by extending it with NotificationCompat.WearableExtender class. Sample notification code can look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.ic_small)
        .setContentTitle(context.getString(R.string.app_name))
        .setContentText(message)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT);
final NotificationCompat.Builder notificationBuilder =
	new NotificationCompat.Builder(context);

notificationBuilder.setContentText("Text on second page")
                   .setSmallIcon(R.drawable.ic_small)

final Notification notificationWear =
extendWearNotification(context, userMessage);

NotificationCompat.WearableExtender wearableExtender =
	new NotificationCompat.WearableExtender()
  	    .setBackground(bitmap)
  	    .addPage(notificationWear);

Notification notification = builder.build();

NotificationManagerCompat.from(context).notify(notificationId, notification);

This will create notification like this:

Big notification

Problem will be if we don’t want to show any text, but only show background only. I was looking quite heavily and found this stackoverflow comment: http://stackoverflow.com/questions/24935426/android-wear-only-picture-no-title-second-page . Seems like solution but… it won’t give you the expected result, you still will end up with the same text message. I have finally found the answer for this is this book: Beginning Android Wearables – ISBN 978-1-484205-18-1 form Apress by Andres Calvo.

What you really need to do is to set setHintShowBackgroundOnly(true) to WearableExtender like in the stackoverflow link and invoke setHintHideIcon(true) method too:

1
2
3
4
5
6
7
final Notification notificationWear = extendWearNotification(context, userMessage);
NotificationCompat.WearableExtender wearableExtender = 
	new NotificationCompat.WearableExtender()
		.setBackground(bitmap)
		.setHintShowBackgroundOnly(true)
		.setHintHideIcon(true)
		.addPage(notificationWear);

Then you should see background only notification.

Background only notification

android wear background notification