I am trying to create an application that can receive images from a directory on an android phone and display them in a layout. It seems that I am working towards the solution in the reverse order. I know to use view.setBackgroundDrawable(Drawable.createFromPath(String pathName));to display the image, but I do not know how to get the path to the image from the directory.
I have a vague idea of what to do, but I would like clarification on this issue. I think the next step is to use:
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
File file[] = Environment.getExternalStorageDirectory().listFiles();
}
But how can I filter files so that only image files are saved in mine file[]? Such as .png or .jpg / .jpeg files? And after that, should I use files[].getPathor files[].getAbsolutePath? I would save the result in String[].
Basically, I ask you to confirm that the above code should work. And also, how can I filter to store only image files such as .png, .jpgand .jpeg.
Thank you for your time.
source
share