5

I am facing issue to display push notification on lock screen. I am able to receive notification but unable to display them on lock screen.

Notification notification;
notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            //.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.drawable.loader)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) //to show content on lock screen
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .build();

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(count, notification);

I had also tried using PowerManager but it only wake up's the lock screen but didn't display notification on screen.

PowerManager powerManager = (PowerManager) mContext.getSystemService(POWER_SERVICE);

if (!powerManager.isInteractive()){ // if screen is not already on, turn it on (get wake_lock for 10 seconds)
    PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MH24_SCREENLOCK");
    wl.acquire(10000);
    PowerManager.WakeLock wl_cpu = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MH24_SCREENLOCK");
    wl_cpu.acquire(10000);
}

As I am new to android I am unable to resolve the issue. Please help me out.

Dumbo
  • 1,630
  • 18
  • 33
Raghunath Raut
  • 442
  • 5
  • 16
  • Is your notification shown in the status bar, once the phone is unlocked? – Christopher Jun 08 '18 at 06:05
  • @Christopher Thanks for your quick replay,The notification are properly displayed on status bar – Raghunath Raut Jun 08 '18 at 06:07
  • 2
    Hmm, but the phone itself is configured to show notifications on the lock screen? As a user you can control whether you want to see notifications on the lock screen or not. – Christopher Jun 08 '18 at 06:10
  • @Christopher Thank you so much .I tried the way suggested by you Its working fine know .But is their any way to automatically select "Show notification on lock screen" tab programatically ? – Raghunath Raut Jun 08 '18 at 06:18
  • For sure you can't manipulate this settings automatically, but you can try to guide the user to the respectively screen in the settings -> https://stackoverflow.com/questions/32366649/any-way-to-link-to-the-android-notification-settings-for-my-app – Christopher Jun 08 '18 at 06:29
  • @Christopher Thanks a lot ,I will try the suggested way . – Raghunath Raut Jun 08 '18 at 06:41
  • https://stackoverflow.com/questions/7442670/android-how-to-show-notification-on-screen?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – VVB Jun 08 '18 at 11:42

0 Answers0