如果使用标志“ FLAG_NO_CLEAR ”,则通知不会显示在Android Wear上。
有谁知道为什么或任何解决方法?我在文档中找不到任何信息。
我的通知上需要标记“ FLAG_NO_CLEAR ”,并具有“关闭”,“暂停”等操作按钮!
通知标志FLAG_NO_CLEAR
基本上使您的通知“正在进行”。通过电话发布的正在进行的通知将不会显示在可穿戴设备上。
您有两种解决方案-两者都有优点和缺点。请阅读下面的文字,并确定哪种解决方案可以更好地解决您的问题:)
您可以利用group
Android Wear框架的功能。它的创建基本上是为了在可穿戴设备上发布许多(分组的)通知,并summary
在电话上发布一个通知。但是使用这种机制,您还可以ongoing
在手机上发布一条通知,仅在穿戴时发布第二条通知。您最终会ongoing
在手机上收到一条通知,在可穿戴设备上收到一条正常通知。
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// This notification will be shown only on phone
final NotificationCompat.Builder phoneNotificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title phone")
.setContentText("Text phone")
.setOngoing(true)
.setOnlyAlertOnce(true)
.setGroup("GROUP")
.setGroupSummary(true);
// This notification will be shown only on watch
final NotificationCompat.Builder wearableNotificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title wearable")
.setContentText("Text wearable")
.setOngoing(false)
.setOnlyAlertOnce(true)
.setGroup("GROUP")
.setGroupSummary(false);
notificationManager.notify(0, phoneNotificationBuilder.build());
notificationManager.notify(1, wearableNotificationBuilder.build());
通过此方法,您可以仅在观看时发布“替代”通知,并将通知保留ongoing
在电话中。但是(如前所述)监视中的通知不能是ongoing
-必须是常规通知。如果您确实想ongoing
在手表上收到真实的通知,则需要寻求第二种解决方案。
请在此处阅读有关分组(堆叠)通知的更多信息:https :
//developer.android.com/training/wearables/notifications/stacks.html
手机上正在进行的通知不会显示在手表上,但是您可以创建Android应用程序的可穿戴部分,然后直接在Android Wear上发布通知。您可以从那里轻松地发布正在进行的通知,但是它不会与电话中的通知相同。您将需要在两个设备之间同步它们。
请DataApi
在此处了解更多信息:
https : //developer.android.com/training/wearables/data-layer/index.html
https://developer.android.com/training/wearables/data-layer/data-items.html
您也可以看一下我的帖子,我在其中发布了演示如何DataApi
在实践中使用a的代码:https :
//stackoverflow.com/a/24896043/3827276
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句