Open RamsayRomero opened 1 year ago
I'm having the same problem, still no solution
@Sang-Nguyen-Sunny I was able to get it to work by following this example but now I have the same issue that they're asking about which is that the app will always bypass the lock screen if the phone is unlocked and in the background. The post has a solution but I don't know how to split my app into multiple activities in React Native so for now this will do. Also note that the example sometimes would not work for me so I added additional code to get it to work.
In my AndroidManifest.xml I added this permission:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
and to my ".MainActivity" activity I appended the following attributes:
android:showOnLockScreen="true" android:showWhenLocked="true" android:turnScreenOn="true"
and I added additional code to the example to request keyguard dismissal, so I ended up with this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true);
setTurnScreenOn(true);
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
keyguardManager.requestDismissKeyguard(this, null);
} getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
and don't forget to import:
import android.view.WindowManager;
import android.app.KeyguardManager;
import android.content.Context;
Not an Android expert so I don't know how much of this code is actually needed but it's working for me. Sometimes the full screen incoming call ui shows up before the app comes to the foreground but the app still actually runs behind it, just like on iOS after receiving a VoIP notification, which is all I need.
adding android:showOnLockScreen="true" android:showWhenLocked="true" android:turnScreenOn="true"
helped me to wake up app from killed locked state, thanks
Bug report
[X] I've checked the example to reproduce the issue. The example doesn't implement backToForeground
Reproduced on:
Description
Calling backToForeground does not open the app when app is killed and locked. Calling backToForeground on all other states works as expected.
Steps to Reproduce
Force quit your app, lock your device, then wake your app with a notification by calling displayIncomingCall and backToForeground from a headless js task. This will show the incoming call screen, but will not cause your app to start.
Versions
Logs
Note that the logs are the same as when I test with the app in a killed state but with my device unlocked. If this is the correct behavior, is there any way I can wake my app in the background on Android when a notification is received, the same way iOS VoIP notifications wake up the app in the background?