Notifications not showing on lock screen Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Notifications not showing on lock screen without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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?

Answer

builder.setOngoing(true)

makes the notification shown on the lock screen.

We are here to answer your question about Notifications not showing on lock screen - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji