gpt4 book ai didi

java - 在 WearOS 中显示多个通知

转载 作者:行者123 更新时间:2023-12-02 09:04:59 25 4
gpt4 key购买 nike

我想显示一些通知,但我只看到一个通知,我这样做了;

public void showNotification(int i){

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01 " + i;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications " + i, NotificationManager.IMPORTANCE_HIGH);

notificationChannel.setDescription("Channel description " + i);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}


NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);

notificationBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("Hearty365")
.setVibrate(new long[]{0, 1000, 500, 1000})
// .setPriority(Notification.PRIORITY_MAX)
.setContentTitle("Default notification")
.setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.setContentInfo("Info");

notificationManager.notify(/*notification id*/1, notificationBuilder.build());

}

这就是我测试显示通知的方式:

for(int i=0 ;i <2 ; i++){
showNotification(i);
}

最佳答案

这里的问题通知ID应该是唯一的

 notificationManager.notify(/*notification id*/1, notificationBuilder.build());

请按如下方式更新

 notificationManager.notify(/*notification id*/(int)(Math.random() * 100), notificationBuilder.build());

关于java - 在 WearOS 中显示多个通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59891820/

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