0

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() {
}
cj7
  • 15
  • 2
  • 3
  • I'm not sure what exactly you're asking, or what the problem is. The UIL should handle loading images with a `file://` scheme just fine. Once you've got the image uris, it's just a matter of loading them into something like a `ListView` or `GridView`. – MH. Jun 12 '13 at 03:23
  • i can't get the image uris. – cj7 Jun 12 '13 at 03:33

1 Answers1

2

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);
    }
 }
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
  • Where should this code put? because in my Constants.java did not have the viewPagerList – cj7 Jun 12 '13 at 03:28
  • inside your "for" where you are fetching your URI. but this will give you converted STRING path of image. – Chintan Rathod Jun 12 '13 at 03:31
  • public static final String[] IMAGES = new String[] { /// the image path /// }; how am i going to fetch the array data go in the new string? Can just put like this ' test.toString() ' ? – cj7 Jun 12 '13 at 03:49
  • no.. array list provides "get()" method, inside that you can provide index of your element like "test.get(10)". And though you have list, there is no need of "Array Of Strings" which is "IMAGES" in you case. Don't make replica of objects. – Chintan Rathod Jun 12 '13 at 03:53