• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Browse picture

Chikabala

Lurker
Hello,
Please how can i browse a picture from androidphone or from SD card and put it in a listView (Android)?
Thank you
 
You can use the Java File API to iterate all files starting from a given directory (e.g. /sdcard) recursively. The API call to get all files in a folder is listFiles.

You can add a file filter (implements FileFilter) to filter out all image files. E.g.

public class ImageFileFilter implements FileFilter {
private final String[] imageFileExtensions = new String[] {"jpg", "jpeg", "png", "gif", "tiff"};

public boolean accept(File file) {
for (String extension : imageFileExtensions) {
if (file.getName().toLowerCase().endsWith(extension)) {
return true;
}
}
return false;
}
}

You need to add this filter to the listFiles call, e.g.
File[] files = dir.listFiles(new ImageFileFilter());

Once you get all the image files you want, you can add those files to the ListView using something like ArrayAdapter.

Hope this helps.

Shengxin

Apps: Secret Locker
 
There is also a class called FileFilter that does a lot of the work.

One thing to watch out for: when decoding bitmaps from a byte stream (file) be sure to only decode the size you need. Otherwise you will hit OOM (out of memory) errors very quickly.

I forget some of the code off the top of my head but I think you use something called a BitmapObject and set it to inDecodeBounds. Then you can get the proportions of the image and decode a down-scaled version of the image.

I think there's a lot on stackoverflow about this but if I get the time I'll post some links and code.
 
There is also a class called FileFilter that does a lot of the work.

One thing to watch out for: when decoding bitmaps from a byte stream (file) be sure to only decode the size you need. Otherwise you will hit OOM (out of memory) errors very quickly.

I forget some of the code off the top of my head but I think you use something called a BitmapObject and set it to inDecodeBounds. Then you can get the proportions of the image and decode a down-scaled version of the image.

I think there's a lot on stackoverflow about this but if I get the time I'll post some links and code.

To expand on what alp said, your app (application in general, not each activity) is.only granted a 20MB portion of the devices total memory to work with at runtime. Memory management J's extremely important in the mobile space.
 
Back
Top Bottom