Native Gallery for Android & iOS [Open Source]

I made a stupid mistake…I forgot to set the texture of the rawImage to Texture2D texture. That’s why I can see nothing but only a white image. And I think the pixel data can be read correctly. Thank you for your help!

Hey @yasirkula !!! Great improvements on your fantastic asset!!! Just one question, on ios can you create a folder inside photos with your asset, and save your photos there from the Application.persistentDataPath of ios?

1 Like

Yes, the NativeGallery.SaveImageToGallery( string existingMediaPath, string album, string filenameFormatted, MediaSaveCallback callback = null ) function will create the specified folder (album) in Photos and save the provided image there. If your image is named image.png and is located at the root of the persistentDataPath, then the following code should do the trick:

NativeGallery.SaveImageToGallery( System.IO.Path.Combine( Application.persistentDataPath, "image.png" ), "Folder Name", "image.png" );

@yasirkula WoowwwwWWW thats awesome :-)))))) have to try it!!! Thank you so much :-)))))))

Would your asset also work to save videos for the application.persistentdatapath to a custom folder on photos of iOS ???

Sure it does :slight_smile:

NativeGallery.SaveVideoToGallery( System.IO.Path.Combine( Application.persistentDataPath, "video.mp4" ), "Folder Name", "video.mp4" );
2 Likes

Thats so cool!! Just what i needed!!! Thank you so much!!! Hope i can repay some day :slight_smile:

Lol, you are welcome!

1 Like

Hi, Great plugin. i love it… But is there a delete from gallery function?
Im currently using File.Delete(savepath)

But in the gallery there is still the thumbnail where the image should have been… Can you assist with this? Thank You.

There is a hidden Delete function (see this topic) but it requires you to know the absolute path of the saved image and it works on Android only.

NativeGallery doesn’t return the absolute path of the saved image/video (mainly because it is inaccessible on iOS). However, if your string filenameFormatted parameter doesn’t contain a {0}, you can get the absolute path of the saved image on Android by making the NativeGallery.GetSavePath function public and then calling it.

Cheers man… thanks alot.

Hello @yasirkula , I want to import an image from the gallery on android, but I don’t know how I have to use this plugin. I am making a puzzle game and I want to puzzle with my own photo’s, but I can’t get this working. I can’t even open the gallery on my phone (maybe that sounds stupid and I looked at your online documentation, but I am a beginner with Unity). Can you help me with this? Thank you.

Here’s a simplified version of the example code:

public Texture2D pickedImage;

public void PickImageFromGallery( int maxSize = 1024 )
{
    NativeGallery.GetImageFromGallery( ( path ) =>
    {
        if( path != null )
        {
            // Create Texture from selected image
            pickedImage = NativeGallery.LoadImageAtPath( path, maxSize );
        }
    }, maxSize: maxSize );
}

After you call the PickImageFromGallery function, you’ll be able to pick an image from the Gallery (if image is larger than maxSize px, it will be downscaled for better memory usage). After you pick an image, it will be stored at the pickedImage variable.

Thank you, for sending the solution. Now I can open the gallery, show the image in my app and it looks gorgious. You have made an amazing plugin!

You are welcome :slight_smile:

Awesome plugin. Thanks a lot. It took me less than 2 minutes to have it working for opening a photo from the gallery.

I had all the rest of the code already working and tested (I was using a system dialog to test it on the editor), so using your plugin was a breeze.

Congrats for the great work and thanks for providing it.

1 Like

Hi @yasirkula ,
I am not able to save video from StreamingAssets in Android/IOS Gallery.
Please help.

On Android, StreamingAssets is bundled inside a .jar/.apk file. You have to extract the file somehow. For example, if you want to save StreamingAssets/image.png to gallery on Android, you can use the following function:

public void SaveImageToGalleryFromStreamingAssets()
{
    StartCoroutine( SaveToGalleryCoroutine() );
}

private IEnumerator SaveToGalleryCoroutine()
{
    string url = System.IO.Path.Combine( Application.streamingAssetsPath, "image.png" );
    WWW www = new WWW( url );
    yield return www;
   
    NativeGallery.SaveImageToGallery( www.bytes, "Album name", "image.png" );
}

Saving from StreamingAssets on iOS should work, though. Are you getting any errors in the console?

Hi @yasirkula Thanks for your revert but i have one more problem regarding Android.
You have mentioned

  • for Android: set Write Permission to External (SDCard) in Player Settings

But is this is possible without External(SDCard) because now Android Smartphones are having enough memory so no one inserts external SDCard.

Please Help in this also

The term “external storage” is a confusing one because it doesn’t actually mean a “removable storage”. AFAIK, it just means the files/directories that your app can’t access to without permission. For example, your app can access its cache/temp directory without permission because it is “internal” storage but your app can’t access images/videos on the device without permission because they are “external” storage. You’ll need Write External Storage permission to write new media to Gallery.

1 Like

Hi @yasirkula Is that possible to save Audio files with your plugin.
Thanks for your support.