簡體   English   中英

在 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());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM