Notifications not showing on lock screen

Ulrich_Peters :

I want to show notifications on lock screen, but I'm unable to get it to work.

This is my code that I have;

                  .setSmallIcon(R.drawable.deleteaccounticon)
                  .setContentTitle("My notification")
                  .setContentText("Much longer text that cannot fit one line...")
                  .setStyle(new NotificationCompat.BigTextStyle()
                          .bigText("Much longer text that cannot fit one line..."))
                  .setPriority(NotificationCompat.PRIORITY_HIGH);

          builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
              CharSequence name = "channel1";
              String description = "test";
              int importance = NotificationManager.IMPORTANCE_HIGH;
              NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
              channel.setDescription(description);
              // Register the channel with the system; you can't change the importance
              // or other notification behaviors after this


              NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
              notificationManager.createNotificationChannel(channel);
              notificationManager.notify(1,builder.build());
              channel.setLockscreenVisibility(VISIBILITY_PUBLIC);
      } 

The notifications is not showing on the lock screen. The settings for the app allows to show notifications on lock screen.

Any advice?

memresubasi :

builder.setOngoing(true)

makes the notification shown on the lock screen.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=133410&siteId=1