I cannot get the watch to vibrate after calling setGroup()
Code:
NotificationCompat.Builder notification = new NotificationCompat.Builder(context); notification.setGroup(GROUP_KEY_NOTIFY); notification.setVibrate(patternArray); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(id, notification.build());
Observations:
- Notification correctly stacked and displayed on the 'Samsung Gear Live'
- No notification on the phone other than a separate summary as intended
- No vibration on the watch whether it is the first or a subsequent stacked notification
Attempts:
- Changed every flag and piece of state that I can find, but nothing helps
- Only solution that restores the watch vibration is to comment out setGroup() in the code above, but that breaks stacking and causes the notification to appear on both the watch and phone
Thanks
UPDATE: SOLUTION
Complete sample code for sending stacked notifications
static boolean CHILD2 = true;
public static void postNotifications(Context context) {
NotificationTest test = new NotificationTest();
Notification[] notifications = test.buildNotifications(context);
for (int i = 0; i < notifications.length; i++) {
Notification not = notifications[i];
NotificationManagerCompat.from(context).notify(i, not);
}
}
private static class NotificationTest {
public Notification[] buildNotifications(Context context) {
// Summary
NotificationCompat.Builder summaryBuilder = new
NotificationCompat.Builder(context)
.setGroup(EXAMPLE_GROUP_KEY)
.setGroupSummary(true)
.setContentTitle("The title")
.setContentText("The text")
.setSmallIcon(R.mipmap.ic_launcher)
.setVibrate(new long[] {0, 1000, 50, 2000} );
// Child 1
NotificationCompat.Builder childBuilder1 = new
NotificationCompat.Builder(context)
.setContentTitle("child 1 title")
.setContentText("child 1 text")
.setSmallIcon(R.mipmap.ic_launcher)
.setLocalOnly(false)
.setGroup(EXAMPLE_GROUP_KEY);
// Child 2
if (CHILD2) {
NotificationCompat.Builder childBuilder2 = null;
childBuilder2 = new NotificationCompat.Builder(context)
.setContentTitle("child 2 title")
.setContentText("child 2 text")
.setSmallIcon(R.mipmap.ic_launcher);
return new Notification[] { summaryBuilder.build(), childBuilder1.build(), childBuilder2.build() };
}
return new Notification[] { summaryBuilder.build(), childBuilder1.build() };
}
}
}
I found the sample in the SDK a little difficult to follow because it uses many classes to assemble the notification. I hope this clears up what needs to be done.
My previous code had 2 problems:
- 'setLocalOnly' was set to 'true' on the summary notification
- 'setVibration' was called on the stacked/child notification instead of the summary notification
Explanation:
It may not be intuitive because the text of the summary notification is not displayed on the watch, BUT it uses the vibration pattern from the summary notification therefore setting it to local only prevents vibration.