In my Application, when a notification arrives, the BroadcastReceiver
is not called if the screen is locked.
But when screen is unlocked, the BroadcastReceiver
is called and displays the notification.
I also put the following permission in my manifest:
android.permission.WAKE_LOCK
But still not working.
Here's the code that works for me:
NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(...);
...
mManager.notify(0, notification);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(15000);
Make sure that you send the notification from your server with delay_while_idle=0
(that's the default value), or the notification won't be sent by GCM until your device wakes up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With