UnityNativeGallery icon indicating copy to clipboard operation
UnityNativeGallery copied to clipboard

Can't get SelectedMediaPath,

Open JackYan666 opened this issue 10 months ago • 3 comments

` E Media uri isn't accessible via File API: content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FScreenshots%2FScreenshot_2025-02-19-11-54-02-286_com.miui.home.jpg java.io.FileNotFoundException: /storage/emulated/0/DCIM/Screenshots/Screenshot_2025-02-19-11-54-02-286_com.miui.home.jpg: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:574) at java.io.FileInputStream.(FileInputStream.java:160) at com.yasirkula.unity.NativeGalleryMediaPickerResultOperation.getPathFromURI(NativeGalleryMediaPickerResultOperation.java:138) at com.yasirkula.unity.NativeGalleryMediaPickerResultOperation.execute(NativeGalleryMediaPickerResultOperation.java:54) at com.yasirkula.unity.NativeGalleryMediaPickerResultFragment$2.run(NativeGalleryMediaPickerResultFragment.java:83) at java.lang.Thread.run(Thread.java:1012) Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Linux.open(Native Method) at libcore.io.ForwardingOs.open(ForwardingOs.java:563) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274) at libcore.io.ForwardingOs.open(ForwardingOs.java:563) at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8648) at libcore.io.IoBridge.open(IoBridge.java:560) at java.io.FileInputStream.(FileInputStream.java:160)  at com.yasirkula.unity.NativeGalleryMediaPickerResultOperation.getPathFromURI(NativeGalleryMediaPickerResultOperation.java:138)  at com.yasirkula.unity.NativeGalleryMediaPickerResultOperation.execute(NativeGalleryMediaPickerResultOperation.java:54)  at com.yasirkula.unity.NativeGalleryMediaPickerResultFragment$2.run(NativeGalleryMediaPickerResultFragment.java:83)  at java.lang.Thread.run(Thread.java:1012) 

Image

`

JackYan666 avatar Mar 03 '25 06:03 JackYan666

After this error occurs, file is copied to temporaryCachePath and its path is returned instead: https://github.com/yasirkula/UnityNativeGallery/blob/4d27475bed66d56aca8b7d585b98fe503525e593/.github/AAR%20Source%20(Android)/java/com/yasirkula/unity/NativeGalleryMediaPickerResultOperation.java#L166

Are you not receiving a path at all? If so, are there other error messages after this one?

yasirkula avatar Mar 03 '25 07:03 yasirkula

Hi. I have this problem too. I need to retrieve the image name. It returns this as a Path, but the "pickedMedia" is not the image name. /storage/emulated/0/Android/data/com.Map.Map/cache/pickedMedia.jpg

ayob-aazami avatar Mar 03 '25 15:03 ayob-aazami

@ayob-aazami Try this in Awake:

#if !UNITY_EDITOR && UNITY_ANDROID
using( AndroidJavaClass ajc = new AndroidJavaClass( "com.yasirkula.unity.NativeGalleryMediaPickerFragment" ) )
	ajc.SetStatic<bool>( "tryPreserveFilenames", true );
#endif

Though read the comment first: https://github.com/yasirkula/UnityNativeGallery/blob/4d27475bed66d56aca8b7d585b98fe503525e593/.github/AAR%20Source%20(Android)/java/com/yasirkula/unity/NativeGalleryMediaPickerFragment.java#L30

yasirkula avatar Mar 03 '25 17:03 yasirkula