[BUG] Black screen when calling register method on Android
Closed this issue · 17 comments
Hello,
I'm using react-native
(version 0.73.6) with expo
(SDK 50) and I have a bug on android Pixel 8 emulator, with Android 14.0 and Android SDK 35.
When I call the register
function from ScreenGuardModule
, i'm getting a totally black screen on my emulator (check screenshot below)
The code is as follow:
useEffect(() => {
ScreenGuardModule.register({
backgroundColor: COLORS.tango,
});
return () => {
ScreenGuardModule.unregister();
};
});
Am I doing something wrong ?
Hi @gfroidcourt. First, Have you eject the Expo module or running npx expo prebuild
yet ?
Second, Can you show me the value of the Colors.TANGO ?
Last, try running on a bare React-native project too see if problem happened.
@gbumps
I ran npx expo prebuild
right after the installation.
For the Colors.TANGO value, it is as follow: #EB6214
.
Last, I experience the same issue in a bare React-native project.
I did:
npx @react-native-community/cli@latest init AwesomeProject
npm install react-native-screenguard --save
Then, in App.tsx
:
useEffect(() => {
ScreenGuardModule.register({
backgroundColor: '#EB6214',
});
return () => {
ScreenGuardModule.unregister();
};
});
And same, a black screen when the app opens.
Are there any problems when using registerWithoutEffect
? If not, i suggest you should use registerWithoutEffect
as a temporary solution for Android 15 while I'm discovering this issue. This might be happened on Android 15, below not detected yet.
Anyway, thanks for reporting.
I don't get the black screen using registerWithoutEffect
. But when I try to do a screenshot, it doesn't block anything. Same for screen recording
Hi @gfroidcourt, try to go to {your_project}/android/build.gradle
and change the compileSdkVersion
and targetSdkVersion
to 33 and rebuild again, as 34+ has some issue with the RECEIVER_EXPORTED
and RECEIVER_NOT_EXPORTED
which caused the black screen happened.
Edited: This is not the problem, but raised another one: When setting to targeted SDK 34+, the app immediately crashed after built successfully. Refer #71 for more info.
Hi @gbumps, thanks for all your answers !
Sadly, I can't downgrade compiledSdkVersion
and targetSdkVersion
to 33 because I have packages that depends on sdk 34.
However, I tried the downgrade in a bare React-native project and I noticed that the registerWithoutEffect
works while I'm recording the screen with XRecorder
, but doesn't works when I'm taking screenshot with the Quick Settings Panel.
If you've run the project expo build successfully but encountered black screen, you might have forgot this step here.
Please revise document, adapt, clean and built project again.
...but doesn't works when I'm taking screenshot with the Quick Settings Panel.
Please show me how you test this on Android Emulator. I've tested registerWithoutEffect
on both Android real device and emulator, all still works fine though.
Hi @gfroidcourt, have you solved the problem yet ? You can reopen this issue again if need.
Thanks and happy hacking!
Still an issue
That works perfectly, thank you, although in the docs a bit hidden under RN 0.59 linking guide, i suggest to place it up front and not under Linking. Also I had to switch to registerWithoutEffect
That works perfectly, thank you, although in the docs a bit hidden under RN 0.59 linking guide, i suggest to place it up front and not under Linking. Also I had to switch to registerWithoutEffect
Thanks for the suggestion, I'll consider it on the upcoming release of react-native-screenguard
Happy hacking!
i have also encountered the same issue.
i was trying to prevent screenshots on only on specific screen only and allow on all other screens.
i have completed linking steps described.
Verisons:
react-native : 75.2
@react-navigation/native-stack: 6.11.0
react-native-screenguard: 1.0.2
Device
Testing device - Android 14 (Physical Samsung device)
Steps to reproduce
- Added 2 buttons on a screen on to with register (empty object passed) and other to unregister
- if we press register button once and it works fine no crash and system message about screen shot not allowed if we try to take screen shot.
issue 1. when we press on register twice screen become black. if we press on back button of hardware app just crash (even if there is a screen to go back in navigation)
issue2. after register even if we press on unregister we can't take screen shots
it works fine with registerWithoutEffect and also unregister works too.
Logcat log in case of calling register twice (Not sure about this i don't have much knowledge about adb or native codes)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: java.lang.RuntimeException: Unable to pause activity {com.srjajoriya/com.screenguard.ScreenGuardColorActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'char java.lang.String.charAt(int)' on a null object reference
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:5780)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.ActivityThread.performPauseActivity(ActivityThread.java:5731)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:5683)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:48)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:180)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:98)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:230)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.os.Looper.loop(Looper.java:319)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8919)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'char java.lang.String.charAt(int)' on a null object reference
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.graphics.Color.parseColor(Color.java:1383)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at com.screenguard.ScreenGuardColorActivity.doCoverByAction(ScreenGuardColorActivity.java:200)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at com.screenguard.ScreenGuardColorActivity.onPause(ScreenGuardColorActivity.java:111)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.Activity.performPause(Activity.java:9188)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1657)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:5770)
10-16 11:31:24.696 14844 14844 E AndroidRuntime: ... 14 more
Hello, I'm having the same issue of black screen in android when using registerWithImage. I'm currently using react native version 0.72.7 and my sdk version is 34. Cannot be downgrade, some package need to be this version.
@ricophie03 please check this and try again reference
@deepktp Did you find a fix for this? I also can use registerWithoutEffect without any issue so I had to switch to it for now