gpt4 book ai didi

Android Wear Preview 堆叠式通知

转载 作者:太空狗 更新时间:2023-10-29 13:24:32 25 4
gpt4 key购买 nike

使用 setGroup 发送堆叠通知时遇到问题。在我调用 setGroup 的那一刻,设备或 Android Wear 模拟器上没有发送任何通知。一些示例代码...

    Intent intent1 = new Intent(this, AddActivity.class);
PendingIntent pIntent1 = PendingIntent.getActivity(this, 0, intent1, 0);

NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
nBuilder.setContentTitle("Fence Monitor").setContentText("FENCE " + status).setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent1);

NotificationCompat.Builder nBuilder1 = new NotificationCompat.Builder(this);
Notification secondNotification = nBuilder1.setContentTitle("Fence Monitor").setContentText("This is additional information related to this notification").setSmallIcon(R.drawable.ic_launcher).build();



WearableNotifications.Action.Builder aBuilder = new WearableNotifications.Action.Builder(android.R.drawable.ic_input_add,"Add Content",pIntent1);
WearableNotifications.Action action = aBuilder.build();

RemoteInput.Builder rBuilder = new RemoteInput.Builder(QUICK_REPLY);
RemoteInput rInput = rBuilder.setAllowFreeFormInput(true).setLabel("QUICK REPLY").build();


WearableNotifications.Builder wBuilder = new WearableNotifications.Builder(nBuilder);
Notification notification = wBuilder.setGroup(FENCE_NOTIFICATIONS_GROUP,order).addAction(action).addPage(secondNotification).addRemoteInputForContentIntent(rInput).build();


//Notification notification = wBuilder.setGroup(FENCE_NOTIFICATIONS_GROUP,order).build();

NotificationManagerCompat nManager = NotificationManagerCompat.from(this);
int notificationId = (new Random()).nextInt();
Log.d("Notification Id",""+notificationId);

nManager.notify(notificationId, notification);

最佳答案

我在玩弄堆叠的通知,并意识到需要有一个摘要通知才能显示您的通知(至少在我的情况下是这样)。安卓文档:https://developer.android.com/wear/notifications/stacks.html#AddSummary提到这很重要,但没有说这是必需的。

无论哪种方式,试试这个,看看它是否有效。通过添加摘要通知,我能够让您的代码正常工作。

    /**
* Create a summary notification
*/
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.alert_dialog_icon);
WearableNotifications.Builder wearableBuilder = new WearableNotifications
.Builder(builder)
.setGroup(FENCE_NOTIFICATIONS_GROUP,
WearableNotifications.GROUP_ORDER_SUMMARY);
Notification summaryNotification = wearableBuilder.build();

/**
* Notify. First publish the summary notification and then send out the
* other multi-page notification.
*/
NotificationManagerCompat nManager = NotificationManagerCompat.from(this);
int notificationId = (new Random()).nextInt();
Log.d("Notification Id",""+notificationId);
nManager.notify(notificationId, summaryNotification);
notificationId = (new Random()).nextInt();
Log.d("Notification Id",""+notificationId);
nManager.notify(notificationId, notification);

关于Android Wear Preview 堆叠式通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22963522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com