Hrushikesh Betai
Hrushikesh Betai

Reputation: 2217

Application does not notify local notification while in sleep mode

I have a task to develop the android application with local push notification. I have also developed the application for that but some times when the user device is in sleep mode it can't notifying on the user device.

Is their any code to execute the application and notify me while my device is in sleep mode.Please provide any example or source for it.

Upvotes: 0

Views: 1667

Answers (1)

Reno
Reno

Reputation: 33792

You're probably should be acquiring a wake lock, like so :

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl =  pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "My Tag");
 wl.acquire();
  ///  ..screen will stay on during this section..
 wl.release();

ACQUIRE_CAUSES_WAKEUP

Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately.

Upvotes: 1

Related Questions