![](/img/trans.png)
[英]Flutter: Android: How can i make unremovable local notification toolbar with some action button on it as shown in screenshot
[英]How can I specify that an Notification action is not shown on Android Wear?
如果我创建通知,我可以添加三个操作。 每个动作也可以在手表上调用。 是否有可能在Android Wear Watch上无法使用此操作?
无论何时在NotificationCompat.WearableExtender
使用addAction()
,您实际上并没有扩展操作(尽管名称),而是将它们分成两个列表,一个用于电话,另一个用于可穿戴设备。
NotificationCompat.Builder
上添加的操作显示在手持设备上。 请参阅指定仅可穿戴操作 :
如果您希望可穿戴设备上的可用操作与掌上电脑上的操作不同,请使用
WearableExtender.addAction()
。 使用此方法添加操作后,可穿戴设备不会显示使用NotificationCompat.Builder.addAction()
添加的任何其他操作。 也就是说,只有WearableExtender.addAction()
添加的操作才会出现在可穿戴设备上,并且它们不会出现在掌上电脑中。
因此,要创建仅限手持设备的操作,请在创建扩展程序之前添加它们。 要进行仅可穿戴动作,请在扩展器上添加它们。 如果您使用扩展器并且想要在两个设备中重复操作,则必须在两者中添加它们(尽管可能有复制它们的选项?)。
例如:
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("The title")
.setContentText("This is the text")
.setContentIntent(pendingIntent);
// Handheld-only actions.
notificationBuilder.addAction(drawable1, "In Both", pendingIntent);
notificationBuilder.addAction(drawable2, "Only in phone", pendingIntent);
// Wearable-only actions.
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
wearableExtender.addAction(new NotificationCompat.Action.Builder(drawable2, "In Both", pendingIntent).build());
wearableExtender.addAction(new NotificationCompat.Action.Builder(drawable3, "Only in wearable", pendingIntent).build());
notificationBuilder.extend(wearableExtender);
// Build and show notification.
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, notificationBuilder.build());
也
WearableExtender
但不向其中添加任何操作,则使用原始通知中的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.