简体   繁体   中英

Oreo: When I use NotificationManager.IMPORTANCE_LOW, notification does not appear in the status bar

When I use NotificationManager.IMPORTANCE_LOW to disable the sound, the notification not appear in the status bar. When I see the setting of a channel I have: Medium No sound.

Here all my code

     Notification notification = notificationBuilder.build();

                                    notification.flags = Notification.FLAG_AUTO_CANCEL;
                                    NotifCmtManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                        if(!checkGroupSon) {
                                             /* Create or update. */
                                            mChannel = new NotificationChannel("comment", "YuYu", NotificationManager.IMPORTANCE_HIGH);
                                            mChannel.enableLights(true);
                                            mChannel.setLightColor(Color.RED);

                                            mChannel.enableVibration(true);
                                            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});


                                            assert mChannel != null;
                                            notificationBuilder.setChannelId("comment");
                                            NotifCmtManager.deleteNotificationChannel("noS");
                                            NotifCmtManager.createNotificationChannel(mChannel);

                                        }else{

                                                  /* Create or update. */
                                           mChannel = new NotificationChannel("noS", "YuYu No Sound", NotificationManager.IMPORTANCE_LOW);
                                            mChannel.enableLights(true);
                                            mChannel.setLightColor(Color.RED);

                                            mChannel.enableVibration(true);
                                            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});

                                            //   mChannel.setSound(null,null);
                                            mChannel.enableVibration(true);


                                            assert mChannel != null;
                                            notificationBuilder.setChannelId("noS");
                                          NotifCmtManager.deleteNotificationChannel("comment");
                                            NotifCmtManager.createNotificationChannel(mChannel);


                                        }
                                    }
                                    NotifCmtManager.notify(ID_NOTIFICATIONCMT, notification);

IMPORTANCE_LOW notification will only be displayed in the status bar if there aren't other higher-importance notifications filling all the status bar space.

To raise the chances of your notification's icon being displayed in the status bar you can use a IMPORTANCE_DEFAULT channel. To disable the sound you can set a null sound to the channel:

mChannel = new NotificationChannel("comment_notSound", "YuYu No Sound",
        NotificationManager.IMPORTANCE_DEFAULT);
mChannel.setSound(null, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM