在 WearOS 中显示多个通知
Display multiple notifications in WearOS
我想显示几个通知,但我只看到一个通知我这样做了;
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());
我想显示几个通知,但我只看到一个通知我这样做了;
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());