6

I have an application which updates a notification through a service.

This notification is updated every second. It shows a timer.

Currently on nougat, with device locked, notification update triggers screen to wake up, to show the updated notification.

I would like to control this as my notification is really frequent.

I would also like to avoid changing the update frequency of the notification. Doing so shows less accurate information to the user.

So what I am looking for is a programmatic way to control wake up screen frequency upon notification updates.

thank you :)

unludo
  • 4,912
  • 7
  • 47
  • 71
  • I'm not sure if you can control the "wake up screen frequency", but why don't you just check if the screen is on before updating the notification? Updating the notification has no meaning when the screen is off. Check [here](https://stackoverflow.com/questions/2474367/how-can-i-tell-if-the-screen-is-on-in-android) to check if the screen is on or off. – Swordsman Jun 01 '17 at 14:00
  • @Swordsman sounds like a good idea, I will try that and let you know. – unludo Jun 01 '17 at 18:33

1 Answers1

3

This below notification can be used to update the user frequently and also the screen will not wake up when locked up. you may try

if(notificationBuilder == null) {
             notificationBuilder =
                     new NotificationCompat.Builder(MainActivity.this)
                             .setSmallIcon(R.mipmap.ic_launcher)
                             .extend(wearableExtender)
                             .setAutoCancel(true)
                             .setContentTitle("Random Notification")
                             .setContentText("Appears!")
                             .setOnlyAlertOnce(true)
                             .setOngoing(true)
                             .setVisibility(Notification.VISIBILITY_PUBLIC)
                             .setContentIntent(contentIntent);
         }else{
             notificationBuilder.setContentText("change this to current updated text");
         }
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainActivity.this);

            notificationManager.notify(888, notificationBuilder.build());
Vishnu Prasad
  • 584
  • 4
  • 11
  • Thanks. I tried it but it does not work. The notification is from a foreground service. So I start it with startForeground. I don't know if it makes a difference. Did you test your solution? – unludo Jun 04 '17 at 10:40
  • Ya I was posting a notification every second with same notification id and using same notification builder. The phone when locked didnt wake. – Vishnu Prasad Jun 05 '17 at 11:24