wake up screen when received notification in Android
Can you update RNPushNotificationListenerServiceGcm.java file
- Import in head:
import android.os.PowerManager; import android.content.Context; - And in on onMessageReceived function:
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if(isScreenOn == false){ PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MyLock"); wl.acquire(10000); PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock"); wl_cpu.acquire(10000); wl.release(); wl_cpu.release(); }don't forget use Try Catch.
can you please submit a PR @huyvm ?
Still have the issue, the notification won't wake up the screen in Android (tried on Xiaomi and Nexus 5).
This issue may be very important.
Find a solution if you are using firebase schedule notification, edit RNFirebaseNotificationManager class.
In the function displayScheduledNotification(), update the case where the App is not in foreground and add :
// If the app is in the background, then we display it automatically
displayNotification(notification, null);
// Turn on the screen for notification
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
if(!isScreenOn){ PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"com.mdcandroid:MyLock"); wl.acquire(10000); PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.mdcandroid:MyCpuLock"); wl_cpu.acquire(10000); wl.release(); wl_cpu.release(); }
Why is it that we need to trigger 2 wakelocks?
WakeLock wl and WakeLock wl_cpu where one is a FULL_WAKE_LOCK and the other is a PARTIAL_WAKE_LOCK. Wouldn't just one with FULL_WAKE_LOCK be sufficient?