Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Native Gallery for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Feb 28, 2018.

  1. DeemaAlyousef

    DeemaAlyousef

    Joined:
    Feb 9, 2022
    Posts:
    4

    Can i see your code please ? i have the same button but i'm struggling with it :(
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    You can call
    NativeGallery.SaveImageToGallery( image, "My Album", "My Image.png" );
     
  3. DeemaAlyousef

    DeemaAlyousef

    Joined:
    Feb 9, 2022
    Posts:
    4
    Thank you for your response !
    the plugin is working now but the size of image is not correct , how can i get the correct size ? below is my current code

    Texture2D texture = new Texture2D(Screen.width / 2, Screen.height,
    TextureFormat.RGB24, false);
    texture.ReadPixels(new Rect(Screen.width / 4, 0, Screen.width / 2, Screen.height), 0, 0);
    texture.Apply();
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    This code grabs a screenshot of the middle half of the screen. If this isn't something you want, then you should remove "/2" and "/4" divisions.
     
  5. DeemaAlyousef

    DeemaAlyousef

    Joined:
    Feb 9, 2022
    Posts:
    4
    Sorry for bothering you..
    I did what you said then the image is captured but it only show grey color not the exact photo.
    Can you please help me with this ?
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Yeah my mistake, you should've changed Screen.width / 4 to 0.
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    The actual error message must be stated in another error log, please check them all out. If the error is "
    attribute android:requestLegacyExternalStorage not found
    ", please see the FAQ in documentation.
     
  8. simoamico94

    simoamico94

    Joined:
    Sep 26, 2017
    Posts:
    1
    Hey yasirkula, first of all thank you for this amazing plugin, it's a life saver! I would like to ask you if I'm doing something wrong. I'm trying to save a video to gallery on a custom album. The same code works in Android creating the folder, but on iOS it saves the video without creating the folder (I can see it in classic Video or Recent folder).
    This is the code I've used:
    Code (CSharp):
    1.             byte[] data = File.ReadAllBytes(lastFilePath);
    2.             string date = DateTime.Now.ToString("dd'-'MM'-'yyyy HH'-'mm'-'ss");
    3.             NativeGallery.SaveVideoToGallery(data, "My Video Capture", "videoRec_" + date + ".mp4", (bool result, string path) => OnVideoSavedToGallery(result,path));
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Yes, unfortunately album name is ignored on iOS 14 and later due to the new permission system on those versions (user must grant full Photos permission but we can't just ask full Photos permission, the permission dialog will always include the irrelevant and confusing "Select Photos..." option).
     
    simoamico94 likes this.
  10. MohsenJamaliL

    MohsenJamaliL

    Joined:
    Nov 13, 2017
    Posts:
    11
    Hi
    I'm having problem with GetImageFromGallery. When I choose an image the screen goes to black and it gets stuck until I turn off the screen and turn it on again
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Can you see any possibly useful logs in logcat?
     
  12. richardzzzarnold

    richardzzzarnold

    Joined:
    Aug 2, 2012
    Posts:
    137
    I have a peculiar situation where I save a video file with NativeGallery. I then delete the video from the iPhones album in the native photos app. I then re open my app and find that the video still exists within my app. How is this? I dont know how to delete it from the app. It still seems to be saved within the app somehow.
     
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Do you mean the video file in persistentDataPath/temporaryCachePath that you've passed to NativeGallery.SaveVideoToGallery? NativeGallery copies that file, it doesn't move it. You can delete the file in MediaSaveCallback, if you wish.
     
    richardzzzarnold likes this.
  14. MohsenJamaliL

    MohsenJamaliL

    Joined:
    Nov 13, 2017
    Posts:
    11
    The device that I'm testing is Android 11 Samsung A71 in Landscape mode only.
    This is only reproducible in Android
    This is my code:

    NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
    {
    Debug.Log("Image path: " + path);
    if (path != null)
    {
    // Create Texture from selected image
    Texture2D texture = NativeGallery.LoadImageAtPath(path, -1);
    if (texture == null)
    {
    Debug.Log("Couldn't load texture from " + path);
    return;
    }
    ProfileImage.texture = (Texture)texture;
    }
    });

    Debug.Log("Permission result: " + permission);

    Write permission is set to External (SDCard)
    enabled "Custom Proguard File" option from Player Settings and added the following line to that file: -keep class com.yasirkula.unity.* { *; }

    and this is the log from logcat
    05-02 12:23:19.545: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): ViewPostIme pointer 0
    05-02 12:23:19.644: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): ViewPostIme pointer 1
    05-02 12:23:19.707: I/Unity(32559): Permission result: Granted
    05-02 12:23:19.804: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): MSG_WINDOW_FOCUS_CHANGED 0 1
    05-02 12:23:25.241: V/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): updateAppliedLetterboxDirection, direction=0, Caller=android.view.ViewRootImpl.handleDispatchLetterboxDirectionChanged:12053
    05-02 12:23:25.243: V/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): updateAppliedLetterboxDirection, direction=0, Caller=android.view.ViewRootImpl.handleDispatchLetterboxDirectionChanged:12053
    05-02 12:23:25.322: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): Relayout returned: old=(977,415,1422,665) new=(977,415,1422,665) req=(445,250)8 dur=44 res=0x5 s={false 0} ch=true fn=5
    05-02 12:23:25.503: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): Relayout returned: old=(91,0,2400,1080) new=(91,0,2400,1080) req=(2309,1080)8 dur=9 res=0x5 s={false 0} ch=true fn=26
    05-02 12:23:25.540: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): stopped(true) old=false
    05-02 12:23:25.553: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): stopped(true) old=false
    05-02 12:23:25.583: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): Relayout returned: old=(977,415,1422,665) new=(977,415,1422,665) req=(445,250)8 dur=15 res=0x5 s={false 0} ch=false fn=-1
    05-02 12:23:25.593: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): Relayout returned: old=(91,0,2400,1080) new=(91,0,2400,1080) req=(2309,1080)8 dur=8 res=0x5 s={false 0} ch=false fn=-1
    05-02 12:23:29.115: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): Relayout returned: old=(977,415,1422,665) new=(977,415,1422,665) req=(445,250)8 dur=3 res=0x1 s={false 0} ch=false fn=-1
    05-02 12:23:29.121: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): Relayout returned: old=(91,0,2400,1080) new=(91,0,2400,1080) req=(2309,1080)4 dur=5 res=0x1 s={false 0} ch=false fn=-1
    05-02 12:23:29.123: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): stopped(false) old=true
    05-02 12:23:29.123: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): stopped(false) old=true
    05-02 12:23:29.125: D/Unity(32559): Selected media uri: content://media/external/images/media/18502
    05-02 12:23:29.149: I/ViewRootImpl@9b8beae[UnityPlayerActivity](32559): setView = com.android.internal.policy.DecorView@d06d1b9 TM=true
    05-02 12:23:29.149: I/ViewRootImpl@9b8beae[UnityPlayerActivity](32559): stopped(false) old=false
    05-02 12:23:29.149: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): stopped(false) old=false
    05-02 12:23:29.149: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): stopped(false) old=false
    05-02 12:23:29.157: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): Relayout returned: old=(977,415,1422,665) new=(977,415,1422,665) req=(445,250)0 dur=5 res=0x7 s={true 2807160480} ch=true fn=-1
    05-02 12:23:29.164: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): Relayout returned: old=(91,0,2400,1080) new=(91,0,2400,1080) req=(2309,1080)0 dur=6 res=0x7 s={true 2807186272} ch=true fn=-1
    05-02 12:23:29.169: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): updateBoundsLayer: shouldReparent = true t = android.view.SurfaceControl$Transaction@7fbf951 sc = Surface(name=Bounds for - com.xxx.xxx/com.unity3d.player.UnityPlayerActivity@1)/@0x656644f frame = 1
    05-02 12:23:29.191: I/ViewRootImpl@9b8beae[UnityPlayerActivity](32559): Relayout returned: old=(0,63,2274,1080) new=(474,358,1891,785) req=(1417,427)0 dur=6 res=0x7 s={true 2807212064} ch=true fn=-1
    05-02 12:23:29.206: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): MSG_RESIZED_REPORT: frame=(977,415,1422,665) ci=(0,0,0,0) vi=(0,0,0,0) or=2
    05-02 12:23:29.206: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): MSG_RESIZED: frame=(91,0,2400,1080) ci=(0,63,126,0) vi=(0,63,126,0) or=2
    05-02 12:23:29.216: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): Relayout returned: old=(977,415,1422,665) new=(977,415,1422,665) req=(445,250)0 dur=4 res=0x3 s={true 2807160480} ch=false fn=1
    05-02 12:23:29.226: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): Relayout returned: old=(91,0,2400,1080) new=(91,0,2400,1080) req=(2309,1080)0 dur=4 res=0x1 s={true 2807186272} ch=false fn=2
    05-02 12:23:29.226: I/ViewRootImpl@9b8beae[UnityPlayerActivity](32559): MSG_RESIZED_REPORT: frame=(474,358,1891,785) ci=(0,0,0,0) vi=(0,0,0,0) or=2
    05-02 12:23:29.232: I/ViewRootImpl@9b8beae[UnityPlayerActivity](32559): Relayout returned: old=(474,358,1891,785) new=(474,358,1891,785) req=(1417,427)0 dur=5 res=0x1 s={true 2807212064} ch=false fn=4
    05-02 12:23:29.252: I/ViewRootImpl@9b8beae[UnityPlayerActivity](32559): dispatchDetachedFromWindow
    05-02 12:23:34.229: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): MSG_RESIZED_REPORT: frame=(91,0,2400,1080) ci=(0,63,126,0) vi=(0,63,126,0) or=2
    05-02 12:23:34.229: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): MSG_RESIZED_REPORT: frame=(977,415,1422,665) ci=(0,0,0,0) vi=(0,0,0,0) or=2
    05-02 12:23:34.254: I/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): Relayout returned: old=(977,415,1422,665) new=(977,415,1422,665) req=(445,250)0 dur=10 res=0x3 s={true 2807160480} ch=false fn=1
    05-02 12:23:34.262: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): Relayout returned: old=(91,0,2400,1080) new=(91,0,2400,1080) req=(2309,1080)0 dur=7 res=0x3 s={true 2807186272} ch=false fn=2
    05-02 12:23:34.280: I/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): MSG_RESIZED_REPORT: frame=(91,0,2400,1080) ci=(0,0,0,0) vi=(0,0,0,0) or=2
    05-02 12:23:34.309: V/ViewRootImpl@9d77aa9[UnityPlayerActivity](32559): updateAppliedLetterboxDirection, direction=1, Caller=android.view.ViewRootImpl.handleDispatchLetterboxDirectionChanged:12053
    05-02 12:23:34.357: V/ViewRootImpl@7ba0264[UnityPlayerActivity](32559): updateAppliedLetterboxDirection, direction=1, Caller=android.view.ViewRootImpl.handleDispatchLetterboxDirectionChanged:12053
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Even if you comment out the code inside GetImageFromGallery, the same issue occurs? I'm trying to figure out if LoadImageAtPath or another code inside GetImageFromGallery might be responsible.
     
  16. MohsenJamaliL

    MohsenJamaliL

    Joined:
    Nov 13, 2017
    Posts:
    11
    No difference, it doesn't reach the call back to print Debug.Log("Image path: " + path);
     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Thank you for testing. Lastly, can you test the plugin on a new Unity project? Sometimes these issues don't occur on new projects and that hints us that the issue is related to some Player Settings or other plugins.
     
  18. MohsenJamaliL

    MohsenJamaliL

    Joined:
    Nov 13, 2017
    Posts:
    11
    You are right I tested it on an empty scene and it doesn't happen. need to figure out what is causing this
     
    yasirkula likes this.
  19. MohsenJamaliL

    MohsenJamaliL

    Joined:
    Nov 13, 2017
    Posts:
    11
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Thank you for sharing your findings. I shall take a look at the package but I'm not completely optimistic about finding a resolution.
     
    MohsenJamaliL likes this.
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    My assumption after some investigation is that AdvertySDK's MonoBehaviorEventsManager.OnApplicationPause and/or OnApplicationFocus functions (located inside
    AdvertySDK.dll
    ) trigger the native UnityController class' pause and resume functions (located inside
    AdvertyAndroidPlugin.aar
    ) which call Unity's own native UnityPlayer class' nativePause and nativeResume functions. In our case, probably pause is triggered but resume isn't for reasons beyond my knowledge.

    I'd recommend you to try changing the following native boolean values of NativeGallery to true/false (try different combinations) and see if any of the combinations resolve the issue: preferGetContent, showProgressbar, useDefaultGalleryApp
    Code (CSharp):
    1. #if UNITY_ANDROID
    2. using( AndroidJavaClass ajc = new AndroidJavaClass( "com.yasirkula.unity.NativeGalleryMediaPickerFragment" ) )
    3. {
    4.     ajc.SetStatic<bool>( "preferGetContent", false );
    5.     ajc.SetStatic<bool>( "showProgressbar", false );
    6.     ajc.SetStatic<bool>( "useDefaultGalleryApp", false );
    7. }
    8. #endif
     
  22. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    117
    There is a bug with Unity's Texture2D.ReadPixels() function on iOS devices while using Display P3 color gamut (Unity 2021.3.x, URP, AR Foundation) ='( Anyone else have the same problem? When I try to save screenshot, it only saves gray/black/white/empty (full alpha) images (result depends on the ReadPixels() and new Texture2D() arguments) to the gallery on iOS devices. Android works without any problem. And ReadPixels() gives "Image blit conversion between formats 83 -> 8 is not supported" or "Image blit conversion between formats 83 -> 7 is not supported" messages. sRGB color gamut has no problem. I also tried "ScreenCapture.CaptureScreenshotAsTexture();" same result.

    I know, this problem is not related to this plugin (and great job, again!), but I think many developers are using this plugin and it is possible to someone have the same problem here.
     
    Last edited: May 17, 2022
    flogskin likes this.
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    TeorikDeli likes this.
  24. wechat_os_Qy0_2_Ao3I-K0jjKE2wAPVU3c

    wechat_os_Qy0_2_Ao3I-K0jjKE2wAPVU3c

    Joined:
    Aug 5, 2019
    Posts:
    2
    Hey, the plugin is super useful, thank you so much.

    One minor question - Can I randomly pick an image / photo from gallery ?
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Unfortunately not. NativeGallery always operates with the image picker user interface.
     
  26. wechat_os_Qy0_2_Ao3I-K0jjKE2wAPVU3c

    wechat_os_Qy0_2_Ao3I-K0jjKE2wAPVU3c

    Joined:
    Aug 5, 2019
    Posts:
    2
    I see. Thanks.
    Another minor question :) Can I pick photos from certain album ?
     
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    At the moment, no. I don't think this will be implemented in the future either.
     
  28. jimmying

    jimmying

    Joined:
    Sep 20, 2017
    Posts:
    105
    Hey @yasirkula

    Quick question:

    With the mediaSaveOmitDCIM option, in the code (below) it says that one of the options is "Videos". I just want to confirm what the options are because "Movies" seems to be working for me on API 29. Is "Videos" a typo?

    Only thing I can find is the following link which refers to "Movies" when accessing shared data:
    https://developer.android.com/training/data-storage/shared/media

    Code (CSharp):
    1.  
    2. //NativeGallery.java line 41:
    3. public static boolean mediaSaveOmitDCIM = false; // If set to true, 'directoryName' on Android 29+ must start with either "DCIM/" or ["Pictures/", "Videos/", "Audio/"]
     
    yasirkula likes this.
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    @jimmying You're right, I apparently wrote it instinctively. Movies is the correct directory for videos.
     
  30. jimmying

    jimmying

    Joined:
    Sep 20, 2017
    Posts:
    105
    Thanks for the confirmation!
     
    yasirkula likes this.
  31. RestlessSwords

    RestlessSwords

    Joined:
    May 9, 2021
    Posts:
    26
    I think iPhone iOS-15.5 broke NativeGallery.GetImageFromGallery
    - I am sure it used to work just fine, and i really like the plugin
    - now, after it is called and user selects an image it 'hangs' for 2+ minutes before returning the path
    - it still works just fine on macOS
    - my iPhone just recently updated to ".5" a week or so ago, I suspect this caused the problem ?

    EDIT (also corrected that it is GetImageFromGallery that hangs):
    a friend is test-flight running my app on their iPhone-15.5 WITH NO PROBLEMS
    - they said iPhone sometimes spazzes, and to try a total power-off, wait 1-2 mins, and restart
    - NOW NATIVE.GALLERY.GetImageFromGallery WORKS FLAWLESSLY AGAIN
    - zero delay. so just a little F.Y.I if anyone else hits it
     
    Last edited: Jun 27, 2022
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    Thank you for the EDIT. The occasional 2 minutes hang is still worrying. I wonder though, whether the issue is caused by GetImageFromGallery or LoadImageAtPath. And it might be helpful if you can check the Xcode console for related error/warning messages during the freeze.
     
  33. RestlessSwords

    RestlessSwords

    Joined:
    May 9, 2021
    Posts:
    26
    I have a debug print right after the GetImageFromGallery calls back, and before LoadImageAtPath
    - it seems that the hang/freeze is before the GetImageFromGallery callback arrives
    - while hung, the Xcode debug screen is empty, but eventually receive the message "Picked an image"
    - - - but still nothing until the callback with the path(i.e. no error messages)
    - after I eventually get the callback with path, the LoadImageAtPath works just fine.
     
    yasirkula likes this.
  34. pouria77

    pouria77

    Joined:
    Aug 13, 2014
    Posts:
    36
    I've used this awesome asset in the past with no issues, but now I got the latest from asset store for another project, and when I try to put the build to an iphone, I get these errors on xcode (screenshot attached).



    Some details:
    My unity version is 2021.3.3
    Xcode version: 13.4

    and the line that uses NativeGallery is this:

    Code (CSharp):
    1.  
    2. string albumName = "Scavenger";
    3. string filename = "animal_" + DateTime.Now.ToString("dd-MM-yyyy_hh-mm-ss") + ".png";
    4. NativeGallery.SaveImageToGallery(myTexture2D, albumName, filename, null);
     
  35. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    @pouria77 Please download the latest version from GitHub since Asset Store is buggy on some Unity versions.
     
  36. pouria77

    pouria77

    Joined:
    Aug 13, 2014
    Posts:
    36
    yasirkula likes this.
  37. Mohanad_GX

    Mohanad_GX

    Joined:
    Mar 10, 2020
    Posts:
    12
    Hi, is there a way to optimize it for low memory devices to prevent crashing ?:(
     
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    CrandellWS likes this.
  39. Mohanad_GX

    Mohanad_GX

    Joined:
    Mar 10, 2020
    Posts:
    12
    I'm actually using it with your image cropper asset, I browse an image from the gallery then pass it to the cropper crop it and pass it to raw image UI, I have a Form like template in my game where players browse images and then upload it to database, it crashes when I browse 10+ images, I tried to lower its resolution it worked but the images now are verry blurry and I don't want that, I'm just wondering if there is another way to do so.
     
  40. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    @Mohanad_GX Uncompressed images can consume a lot of RAM and it increases exponentially as the image size increases. Decreasing maxSize is the most sensible solution. Also make sure that you manually Destroy textures that're no longer needed (e.g. you can Destroy the texture returned by NativeGallery after cropping it, if you no longer need that uncropped texture). Also, on latest Unity versions, you can compress the texture at runtime to reduce its size, though I don't know how efficient it will be for NPOT textures.
     
  41. xurshudyan-narek

    xurshudyan-narek

    Joined:
    Jan 23, 2020
    Posts:
    2
    Hi all.
    @yasirkula thank you very much, its great.
    Is there a way to open gallery inside unity canvas?
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
  43. xurshudyan-narek

    xurshudyan-narek

    Joined:
    Jan 23, 2020
    Posts:
    2
    Тank You for answer.
     
    yasirkula likes this.
  44. ahrarjaved

    ahrarjaved

    Joined:
    Feb 17, 2022
    Posts:
    1
    Hi,
    I am facing an issue regarding saving and then loading the images, as images are saving and loading just fine on unity editor (2020.3.3 lts). Issue is on Android Device, as the path it returns in Android folder, while the file is stored in our Gallery (DCIM), i am confused about its location. I went through the thread, most of them says use GetImagesFromGallery but what would be the path. thanks.
     
  45. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    @unity_eS3X6CjRgO-64A SaveImageToGallery will return the saved image file's path on Android, yes. It can be a raw file path or an abstract Storage Access Framework path as stated in the documentation. In the latter case, you really can't do anything with that path since it's useless outside native Android codes. If a raw file path was returned, then it's great, you can use LoadImageAtPath to load that image at a later time (as long as the image isn't deleted or moved by the user).
     
    ahrarjaved likes this.
  46. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    281
    Hello!
    I get this error when I try to save an image:

    AndroidJavaException: java.lang.IllegalArgumentException: MIME type application/octet-stream cannot be inserted into content://media/external/images/media; expected MIME type under image/*

    What I am doing wrong?
     
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    @Ikaro88 You need to explicitly add extension to filename parameter while calling SaveImageToGallery.
     
    Ikaro88 likes this.
  48. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    281
    this solve to me, thanks a lot!!!!
     
    yasirkula likes this.
  49. adair95

    adair95

    Joined:
    Feb 15, 2022
    Posts:
    10
    hello how are you, it is a super excellent plugin but I have a problem that for the version of unity 2019.4.35fi, they do not work for me, it is script instead for later versions if it works, what would be the problem, I am using the plugin to take a screenshot and I do it with the following script.

    public void TomarFoto()
    {

    StartCoroutine(Desactivar());
    }

    IEnumerator Desactivar()
    {
    yield return new WaitForEndOfFrame();

    Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

    ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);


    ss.Apply();

    string Foto = "imagen" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png";

    NativeGallery.SaveImageToGallery(ss, "Mis Fotos", Foto);



    Destroy(ss);


    }
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,799
    @adair95 Hi! This code looks fine to me. Can you check logcat for error messages?