Question

i get an example from here https://github.com/nostra13/Android-Universal-Image-Loader

In the Constants.java is for the image source link. The thing that i want is scan the specific folder in sdcard, then get all image url in dynamic.

Not one by one type the image url. Not this type one by one. ---> "file:///sdcard/Universal Image Loader @#&=+-_.,!()~'%20.png"

Here is my code. But it can't work. Any solution about this? Thanks.

public class Constants {

private String[] mFileStrings;
private File[] listFile;   
static List<String> test = new ArrayList<String>();


public void getFromSdcard()
{
    System.out.println("testing here can");
   File file= new File(android.os.Environment.getExternalStorageDirectory(),"file:///sdcard/bluetooth/"); //sdcard/bluetooth

        if (file.isDirectory())//if files is directory
        {

            listFile = file.listFiles();
            mFileStrings = new String[listFile.length];

            for (int i = 0; i < listFile.length; i++)
            {
                mFileStrings[i] = listFile[i].getAbsolutePath();//mFileStrings with uri of images
                test.add(listFile[i].getAbsolutePath());

            }

        }

}


static String simpleArray = test.toString();

//String img = mFileStrings.toString();
public static final String[] IMAGES = new String[] {simpleArray};


private Constants() {
}
Was it helpful?

Solution

To get image from sdcard, use following code.

String fileName= listFile[i];
fileName = fileName.replace(':', '/');
fileName = fileName.replace('/', '_');
String loadURL="file://"+Environment.getExternalStorageDirectory()+"/"+folder+"/"+fileName;

Now, you have absolute path of your image in "loadURL".

if (file.isDirectory())//if files is directory
{
    listFile = file.listFiles();
    mFileStrings = new String[listFile.length];

    for (int i = 0; i < listFile.length; i++)
    {
         String fileName=listFile[i]; 
         fileName = fileName.replace(':', '/');
         fileName = fileName.replace('/', '_');
         String loadURL="file://"+Environment.getExternalStorageDirectory()+"/"+folder+"/"+fileName;
         test.add(loadURL);
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top