Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android 11+] StrictMode raising an IllegalAccessException due to usage of non-visual context #688

Open
joaolucas95 opened this issue Jan 11, 2022 · 0 comments

Comments

@joaolucas95
Copy link

joaolucas95 commented Jan 11, 2022

Description of the problem:

In Android 11 or above devices, StrictMode is raising an IllegalAccessException due to the new restrictions of non-visual Context usages when handling UI.

This is happening when calling BarcodeView#resume() and it is caused due to usage of application content to get the WindowManager in RotationListener#listen() method.

Which library version are you using? 4.1.0

Which phone/tablet are you using, and which Android version does it run? (e.g. Samsung Galaxy S5,
Android 5.0)
Pixel 2, Android 12

Does the same happen on other devices or an emulator? It happens on all Android 11 or above devices

In the case of an error do you have a stack trace or adb logs?
2022-01-10 16:31:54.646 15047-15047/------ E/ContextImpl: Tried to access visual service WindowManager from a non-visual Context:--------@1350853 WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:-----Application@1350853
at android.app.ContextImpl.getSystemService(ContextImpl.java:2059)
at android.content.ContextWrapper.getSystemService(ContextWrapper.java:857)
at com.journeyapps.barcodescanner.RotationListener.listen(RotationListener.java:36)
at com.journeyapps.barcodescanner.CameraPreview.resume(CameraPreview.java:633)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant