Android: How to get image files from directory into view.setBackgroundDrawable()
<p>I'm trying to make an app that can take images from a directory on the android phone and display them in a layout. I seem to be working my way towards a solution in a backwards manner. I know to use <code>view.setBackgroundDrawable(Drawable.createFromPath(String pathName));</code> to display the image, but I don't know how to get the image's path from the directory.</p>

<p>I have a vague idea of what to do, but would appreciate clarification on this matter. I think the next step is to use:  </p>

<pre><code>String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    File file[] = Environment.getExternalStorageDirectory().listFiles();
}
</code></pre>

<p>But how do I filter the files so that only image files get stored in my <code>file[]</code>? Such as .png or .jpg/.jpeg files? And after that, should I use <code>files[].getPath</code> or <code>files[].getAbsolutePath</code>? I would store the result in a <code>String[]</code>.</p>

<p>What I am mainly asking for is verification that the above code should work. And also, how I might filter to store only image files such as <code>.png</code>, <code>.jpg</code> and <code>.jpeg</code>.</p>

<p>Thank you for your time.</p>
