4

Basically, I am wondering if it is possible to create two different notifications and how - one for Android Device and other for Android Wear?

For example: I want to have just setContentText, but on Android device I want setContentTitle and setContentText

There is currently no possibility to show notification just on Wear (like setLocalOnly with device only - look for more).

Community
  • 1
  • 1
gabriel.gircenko
  • 123
  • 1
  • 10
  • If you have an wear app you can create a notification from that app, you can use the messaging layer to trigger it. – Raanan Aug 07 '14 at 15:13

4 Answers4

3

I think the Synchronized Notifications sample that comes with the Android Wear SDK may be useful to look at. It gives three simple types of notifications: (1) A phone-only notification (2) A watch-only notification (3) A pair of synchronized phone and watch notifications where the content shown on the watch notification is different from the one on the phone. They are synchronized in the sense that dismissing one results in dismissal of the other one; all based on the Data Layer apis.

I think the third use case is most relevant to you.

Tony Wickham
  • 4,706
  • 3
  • 29
  • 35
  • Where did you find this information? I can't find that anymore in the docs. – Janusz Aug 30 '14 at 10:24
  • I don't think it was in the docs, I just looked at the sample code and found that it did the three things specified above. The sample code is included in the Android Wear SDK, so you can download it from the SDK manager. – Tony Wickham Aug 30 '14 at 22:32
  • There is no Wear SDK anymore in the SDK manager. Everything is inside the Android 20 samples now. And they changed a lot compared to the Wearable Preview SDK – Janusz Aug 31 '14 at 09:06
3

Officially it is not possible to create two different notifications for wear and the phone without writing your own Android Wear App extension. It is only possible to define a notification that is only shown on the phone with NotificationCompat.Builder.setLocalOnly(true)

To create a Notification that is only shown on a Wear Device however you can (at the moment) add the Notification to a group with NotificationCompat.Builder.setGroup(randomGroupKey) and omit the display of a group summary notification. If a notification belongs to a group it is not displayed on the phone because the phone will only show the summary notification. If there is no summary you get a notification for your watch only. Just generate a random group key for every watch only notification.

Officially it is only possible to create a notification that looks different on a smartwatch.

For this use a WearableExtender. For example this code snippet:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(getString(R.string.smaple_notification_title));
builder.setSmallIcon(R.drawable.ic_message);
builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ActivateActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));

NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
extender.setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.notif_background));
extender.setContentIcon(R.drawable.ic_message);
extender.setHintHideIcon(true);
extender.extend(builder);

builder.setPriority(NotificationCompat.PRIORITY_LOW);
builder.setContentText(notificationText);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_icon));
notificationManager.notify(messageIndex, builder.build());

Sets a special background for the notification, hides the app icon that is normally displayed on the notification, and adds a new icon to the preview of your Notification in the "screen off" mode of the watch.

Janusz
  • 187,060
  • 113
  • 301
  • 369
  • This is Working one. And by the way, extend the WearableExtender do not make the group summary visible only on wear. It is shown on phone too... – Nick Jian Oct 14 '14 at 14:57
1

I don't know if there is a way to do exactly what you want but I try to use stack & summary to bypass this: an contentText only notification has been hidden by a summary notification with contentText and contentTitle. On the Android Wear however summary is not being displayed but all the stacked notification (in your term is the notification with only contentText) can be shown.

Tamaki Sakura
  • 482
  • 5
  • 22
1

Yes, It is possible. Steps -

  1. Intercept your Notifications on Handheld by implementing BroadcastReceiever
  2. Generate Notification for Handheld using NotificationBuilder - use setLocalOnly to duplicating it with Wearable
  3. Send Notification data in Message to Wearable - using MessageApi
  4. Extract receieved data & generate Notification for Wearable
Vintesh
  • 1,657
  • 1
  • 24
  • 31