I am trying to build an android app which lists all the files from the SD card that contain a specific extension. For e.g: pdf,mp3,txt etc.
I have tried using the android MediaStore class' getContentURI method.
MediaStore.Files.getContentUri("");
But this is supported only on Honeycomb and higher versions whereas my app needs to support gingerbread too.
Another method that i came across is the apache's FileUtils class, the code of which is shown below.
File externalContentDirectory=Environment.getExternalStorageDirectory();
String[] extensions = new String[] {"mp3","pdf","txt"};
Collection<File> files=FileUtils.listFiles(externalContentDirectory, extensions,true);
The problem is that it takes too much time to list all the files on slower phones and many times the application crashes due to this.
Is there any other android-specific method to list the files that is faster and efficient?