gree / unity-webview

zlib License
2.3k stars 694 forks source link

Access camera on Android 10+ #710

Open chernyadev opened 3 years ago

chernyadev commented 3 years ago

Hello!

I've faced an issue accessing file uploading dialogue on Android 10+ devices (works perfectly for lover versions). I only can attach files from the gallery but am not able to take new pictures. It seems to be related to issues described on Stackoverflow:

Please let me know if that problem could be resolved with any kind of manifest magic or I'm doing something wrong. Thank you in advance!

Best regards!

KojiNakamaru commented 3 years ago

I fixed the code and updated binaries. Could you please try the latest.

eb0KrY4k commented 3 years ago

I fixed the code and updated binaries. Could you please try the latest.

In android 11, this problem is observed on some devices.

KojiNakamaru commented 3 years ago

Settings for allowing camera access with file input field are a bit complicated.

https://github.com/gree/unity-webview/tree/acc3c327128d5ffb71d619fb79d08dc16199f03b#file-input-field https://github.com/gree/unity-webview/tree/acc3c327128d5ffb71d619fb79d08dc16199f03b#cameraaudio-permissionfeature

In short, you should

Could you please check these settings?

eb0KrY4k commented 3 years ago

Settings for allowing camera access with file input field are a bit complicated.

https://github.com/gree/unity-webview/tree/acc3c327128d5ffb71d619fb79d08dc16199f03b#file-input-field https://github.com/gree/unity-webview/tree/acc3c327128d5ffb71d619fb79d08dc16199f03b#cameraaudio-permissionfeature

In short, you should

  • set Player Settings/Other Settings/Write Permission to External (SDCard)
  • define UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
  • invoke webViewObject.SetCameraAccess(true);

Could you please check these settings?

Could you tell me at what point it is better to do this? before launching the application or at the time of creating a webview? it turns out that on xiaomi (11 android) and samsung (11 android) the camera works correctly, but on realme and zte it does not work

KojiNakamaru commented 3 years ago

How far does the app go? Can you see a popup like the following when you tap a file input button?

image

eb0KrY4k commented 3 years ago

How far does the app go? Can you see a popup like the following when you tap a file input button?

image

I see this window, I can open the camera, take a photo, but when I click the confirmation icon, "Camera error, unable to save photo or video" appears

KojiNakamaru commented 3 years ago

Thank you for the report. I investigated further and introduced a fix for Android 7 or later in #743 . Could you please try the latest?

eb0KrY4k commented 3 years ago

Android 10 camera won't launch, on Android 11 devices where the camera didn't launch now crashes. But if you first open "Files" and then "Camera", then everything works fine on Android 11. I experimented: if I add uses-permission android: name = "android.permission.MANAGE_EXTERNAL_STORAGE" in the manifest and give permissions to all files, it works on android 11, but if I cancel the photo, then the next time I open the camera, the app crashes.

KojiNakamaru commented 3 years ago

Could you please upload the sample app project that reproduce the issue? I would like to check various settings, the unity version, etc. to reproduce issues. Could you please also upload adb logcat output when any crash happened? It would be a clue to figure out the cause.

eb0KrY4k commented 3 years ago

Logs: https://pastebin.com/4EAi4asj Test Project: https://drive.google.com/file/d/1sPRbcyEM4_hgZGtUrKQCpJfrU3WG9dJ0/view?usp=sharing

KojiNakamaru commented 3 years ago

Thank you for those files. Though I couldn't reproduce the issue on my OSCAL Pad 8 (Android 11, https://www.devicespecifications.com/en/model/8edb570f ), I found a similar behavior on emulator. I adjusted the logic and the build process in https://github.com/gree/unity-webview/pull/745 and https://github.com/gree/unity-webview/pull/744 so could you please try the latest? Please note the latest binaries don't contain Assets/Plugins/Android/core-1.6.0.aar (instead it contains Assets/Plugins/Android/core-1.6.0.aar.tmpl) so you need to remove Assets/Plugins/Android/core-1.6.0.aar.

BTW, the log you sent seems to show some native code crash. This might happen because of graphics driver's instability. If OpenGLES3 is sufficient for your project, limiting the graphics api to OpenGLES3 could also help bring stability.

eb0KrY4k commented 3 years ago

Thanks, everything works fine now

eb0KrY4k commented 2 years ago

After recent updates, the camera stopped working again

Thank you for those files. Though I couldn't reproduce the issue on my OSCAL Pad 8 (Android 11, https://www.devicespecifications.com/en/model/8edb570f ), I found a similar behavior on emulator. I adjusted the logic and the build process in #745 and #744 so could you please try the latest? Please note the latest binaries don't contain Assets/Plugins/Android/core-1.6.0.aar (instead it contains Assets/Plugins/Android/core-1.6.0.aar.tmpl) so you need to remove Assets/Plugins/Android/core-1.6.0.aar.

BTW, the log you sent seems to show some native code crash. This might happen because of graphics driver's instability. If OpenGLES3 is sufficient for your project, limiting the graphics api to OpenGLES3 could also help bring stability. After recent updates, the camera stopped working again

KojiNakamaru commented 2 years ago

How doesn't it work? Changes since the last time are the followings:

https://github.com/gree/unity-webview/compare/81d56f3...ffbf3c1

and they don't contain any change directly related to camera. The sample app and its binary that runs on my devices can be found in the following, so could you please try it.

https://github.com/gree/unity-webview/issues/751#issuecomment-969999711 (https://github.com/gree/unity-webview/tree/992d2006ae1503f1df44a1fef69d774fcd95acf0/sample is for 2020.3.22f1, which can be easily upgraded to 2021.x).

eb0KrY4k commented 2 years ago

Hello. All the same, camera crashes are observed, the latest version of the plug-in and your Sample are used. If the crash didn't work the first time, you can reset the app and try again. Apk and logs: https://drive.google.com/file/d/1KDOL5sFedvnGuR3FX9FXrku17DWGa9dl/view?usp=sharing

eb0KrY4k commented 2 years ago

Do I have a plugin with android native functionality? in it, the camera works fine, if I can throw it off for comparison.

KojiNakamaru commented 2 years ago

Your app worked okay on my devices.

I couldn't test further as a sort of reCAPTCHA was displayed and I couldn't input Cyrillic glyphs.

Your log contains some vulkan-related messages so I guess you enabled vulkan for your app. As vulkan is rather unstable on some devices, disabling it could help.