How to get sdcard and return and massage files from a specific format?

I need to get sdcard and return files of different formats. The location will be entered by the user. How can I do this programmatically?

+4
source share
1 answer

Simondid, I believe that this is what you are looking for.

Access to sdcard: reading a specific file from sdcard in android

Keep in mind when checking media availability: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

Creating a file filter: http://www.devdaily.com/blog/post/java/how-implement-java-filefilter-list-files-directory

An example of an mp3 file filter. Create the following filter class:

import java.io.*; /** * A class that implements the Java FileFilter interface. * It will filter and grab only mp3 */ public class Mp3FileFilter implements FileFilter { private final String[] okFileExtensions = new String[] {"mp3"}; public boolean accept(File file) { for (String extension : okFileExtensions) { if (file.getName().toLowerCase().endsWith(extension)) { return true; } } return false; } } 

Then, based on an earlier record of access to the SD card, you should use a filter as follows:

 File sdcard = Environment.getExternalStorageDirectory(); File dir = new File(sdcard, "path/to/the/directory/with/mp3"); //THIS IS YOUR LIST OF MP3's File[] mp3List = dir.listFiles(new Mp3FileFilter()); 

NOTE. The code is coarse, you probably want to make sure the SD card is accessible as described above.

+6
source

All Articles