react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

wake up screen when received notification in Android

Open mrminhhuy opened this issue 7 years ago • 4 comments

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.

mrminhhuy avatar Jan 13 '19 07:01 mrminhhuy

can you please submit a PR @huyvm ?

Faolain avatar Mar 23 '19 18:03 Faolain

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.

waredjal avatar Apr 24 '19 09:04 waredjal

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(); }

waredjal avatar Apr 25 '19 15:04 waredjal

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?

Shane-Loong avatar Jul 07 '20 20:07 Shane-Loong