Step-by-step instructions on how to get a picture from photo gallery

ANDROID

I want to pick image from the android picture gallery.

I have googled for over 4 hours, and have not found any free, working method to pick an image from the android picture gallery.

These are the best options I have:

However, they are paid software from the Unity Asset store.

I can not afford paid assets.

I have also found this alleged API:

However, it does not have any documentation, and when I put the plugins into my unity project and install it on an android phone, it fails to run.

May I have clear, step-by-step instructions on how to get a picture from the android picture gallery.
Here are the details of what I need:

  • Freeware only
  • Detailed instructions, what libraries or plugins are needed? Where to download them?
  • What functions to call to initialize? What functions to call to open the android gallery?
  • Retrieve the chosen picture in the form of Texture2D or Sprite.

It will help me greatly, and hopefully, others who’s finding a solution too.

You can use System.IO class to list images from specific directory and select them.
For learning IO class, you can refer to .Net Framework forums and tutorial pages. It’s very helpful in a lot of cases.

For the past 1 hour, I have been searching for what you said, but have not found any leads to a solution.
I have a very simple request:
I want Android’s default photo gallery to open up, where the user can select a photo.
I want the selected photo to be assigned to “chosenPhoto”.

Sprite chosenPhoto;

May I have step-by-step intructions here?
I will help me + likely many other people.

2 Likes
using UnityEngine;
using UnityEngine.UI;
using System.IO;

public class ImagePicker : MonoBehaviour {

    [SerializeField] InputField inf;
    [SerializeField] Reporter rep;

    public void OnClickDir () {
        rep.clear();
        PrintFolders(inf.text);
    }
    void PrintFolders(string path){
        foreach(string x in Directory.GetDirectories(path)){
            Debug.Log(x);
        }
    }
    public void OnClickFil () {
        rep.clear();
        PrintFolders(inf.text);
    }
    void PrintFiles(string path){
        foreach(string x in Directory.GetFiles(path)){
            Debug.Log(x);
        }
    }
}

This is the closest I’ve been to. It’s on an empty project, with “Reporter” from Log Viewer, so that I can see the debug logs on an android device.

The methods OnClickDir, and OnClickFil, are functions that will be called by buttons on click. OnClickDir is called by a button “View Directories”, and OnClickFil is called by a button “View Files”.

The InputField “inf” is an InputField where I can enter the path I would like to check out.

I built the project into an APK, then installed it on my android phone.
I took a photograph using the camera in my phone, and used the built-in “My Files” app to find the location of the taken photograph.
I found out that it was in the “/sdcard/DCIM/Camera/P_20170113_085946.jpg”.

Then, I opened up my app to view the directory with path “/sdcard/DCIM/Camera/”. The directory showed up as empty.

Then, I went to the directory using the built-in “My Files” app, and then created an empty folder, and called it “qwert”.

Then, I opened up my app to view the directory with path “/sdcard/DCIM/Camera/”. Now, an empty folder “qwert” appears. This confirms that I’m viewing the correct directory. However, I can’t see any photographs thru my app.

Why is this so?

I don’t notice any difference between OnClickDir, vs OnClickFil. What’s the difference?

EDIT: OOPS! I just saw that OnClickFil calls PrintFolders, not PrintFiles. Hold on while I re-test this program.

I managed to list the .jpg paths by using PrintFiles. However, what if the image isn’t in the “/sdcard/DCIM/Camera/” directory? Isn’t there an android built-in photo selector API?

I am also struggling for two days to load device gallery image as a material diffuse image and appling on plane in runtime.

1 Like

Did you Got Any solution…
Actually we are also doing same. In may case it causes problem in low space memory(1GB RAM). In low space device it does not load successfully and just restarts app.

We have Media Library feature in our Cross Platform Native Plugins available on Asset store which can do the required job.
It allows to pick an image from gallery or camera and gives you a texture in the callback.

Please ping us if you need any further help.

Thanks,
VB Team

Have you got complete solution? If you got it then please share.

Is this feature available in the free version?

https://github.com/yasirkula/UnityNativeGallery
use this to implement the gallery functionality, works flawlessly for me. the readme has instructions for importing it. though I’m still searching for an extended version of this which gives an option to open camera as well.

Been holding on just kidding, have you got a solution for it? I’m not getting any solution for this…
Please let me know if you created your solution.

Hello, The link is broken, where is the new version of your plugin?

I tried it but it does nothing in my case, don’t know why :frowning:

Have you got any solution for it?

the best way Native Gallery for Android & iOS | Integration | Unity Asset Store

1 Like