MediaPipeUnityPlugin
MediaPipeUnityPlugin copied to clipboard
Some Androids (E.g. HUAWEI) cannot properly wait for camera permissions
Plugin Version or Commit ID
v0.10.3
Unity Version
2021.3.4f1
Your Host OS
win11
Target Platform
Android
Target Device
No response
[Windows Only] Visual Studio C++ and Windows SDK Version
No response
[Linux Only] GCC/G++ and GLIBC Version
No response
[Android Only] Android Build Tools and NDK Version
No response
[iOS Only] XCode Version
No response
Build Command
python build.py build --android arm64 --android_ndk_api_level 21 -vv
Bug Description
Open the apk for the first installation,it doesn't work It works the second time you open it I think "Callback RequestUserPermission" should be used
https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html
#if UNITY_ANDROID
if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
{
+ bool permissionResponse = false;
+ var callbacks = new PermissionCallbacks();
+ callbacks.PermissionDenied += (string permissionName) => { permissionResponse = true; };
+ callbacks.PermissionGranted += (string permissionName) => { permissionResponse = true; };
+ callbacks.PermissionDeniedAndDontAskAgain += (string permissionName) => { permissionResponse = true; };
+ Permission.RequestUserPermission(Permission.Camera, callbacks);
+ yield return new WaitUntil(() => permissionResponse);
- Permission.RequestUserPermission(Permission.Camera);
- yield return new WaitForSeconds(0.1f);
}
#elif UNITY_IOS
Steps to Reproduce the Bug
open apk
Log
no log
Screenshot/Video
No response
Additional Context
No response
no log
Will you share the Player.log? (e.g. adb -s [device_id] logcat Unity:V native:V tflite:V CRASH:E AndroidRuntime:E "*:S")
https://user-images.githubusercontent.com/17309378/212228720-8e3bb10a-4e1a-4129-bde0-a3676a4b2ba2.mp4
i add debug log in script "Start RequestUserPermission" "End RequestUserPermission"

Thanks! Does the code you suggested fix this issue on your device?
Thanks! Does the code you suggested fix this issue on your device?
The problems in the video don't come up every time, but give me some time and I'll test the code fully
I think 0.1sec is simply too short (but waiting for a fixed time is not a good approach).
yield return new WaitForSeconds(0.1f);
I think 0.1sec is simply too short (but waiting for a fixed time is not a good approach).
yield return new WaitForSeconds(0.1f);
According to the unity Android Permissions documentation, callback should be used Using callbacks eliminates the need to write a fixed time
According to the unity Android Permissions documentation, callback should be used
Will you tell me where they say so?
I'm not sure, but I guess this error is caused because the access to _IsPermitted from the Play method is not guarded with _PermissionLock (and if it's guarded, maybe we can remove the WaitForSeconds).
https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L197-L200
https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L147-L152
According to the unity Android Permissions documentation, callback should be used
Will you tell me where they say so?
I'm not sure, but I guess this error is caused because the access to
_IsPermittedfrom thePlaymethod is not guarded with_PermissionLock(and if it's guarded, maybe we can remove theWaitForSeconds).https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L197-L200
https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L147-L152
i think "PermissionCallbacks_PermissionDenied" function is call when user click screen,
this is doc url
https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html

I mean, they say we can use callbacks but don't say we should use callbacks, do they?
I mean, they say we can use callbacks but don't say we should use callbacks, do they?
unity Document not say we should use what code
@jsaon-L Will you check if #829 fixes this issue?
i will test this
您会检查#829是否解决此问题吗?
After my testing this submission does not solve this problem