Android Wear Specific Notification

2020-06-09 07:49发布

问题:

The WearableNotifications.Builder setLocalOnly method can be used for displaying a notification on a phone only, and not mirror it to a Wear device.

Is there a way to do the opposite, so creating a notification that will display only on the Wear device?

回答1:

Actually you can do it using .setMinPriority() on the wearable notification (while it's not official, it works for now)

 Notification summaryNotification = new WearableNotifications.Builder(builderG)
        .setGroup(GROUP_KEY_MESSAGES, WearableNotifications.GROUP_ORDER_SUMMARY)
        .setMinPriority() 
        .build();


回答2:

There is no way to specify an entire notification should not be displayed locally. However, the final notification extensions API (released 6/25), there is a way to specify actions which should only appear on a wearable.

To do this, add the actions wrapped in a WearableExtender:

NotificationCompat.Builder builder = new NotificationCompat.Builder();
builder.extend(new NotificationCompat.WearableExtender()
    .addAction(new NotificationCompat.Action(
        R.drawable.reply, "Reply", pendingIntent)));


回答3:

For the official SDK as per this question on Android Wear Developers Google+ page:

You can use the same notification APIs on the wearable that you use on a phone by writing an android wear app. If you need to trigger that notification from the phone, you can use the Wearable apis in Google Play Services to send messages to trigger them.



回答4:

There is a trick to add a notification for the wear device only.

Add the notification to a group with NotificationCompat.Builder.setGroup and don't display a summary notification for this group. The phone will only display the summary notifications, since there isn't one nothing is displayed on the phone. Just create a random group string for every notification that should only be displayed on the phone.



回答5:

Notification drives through Handheld only, So in order to just show Notification on wear only a possible way to intercept Notification on Wearable then just send message to Wearable for Generating Notificaiton don't generate for Handheld. These steps can help.