0

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?

Nikhil Joshi
  • 97
  • 1
  • 6
  • refer this link [Get Specific Format Files] : http://stackoverflow.com/questions/10381270/how-to-get-all-image-files-available-in-sdcard-in-android – Richa May 18 '13 at 11:13

1 Answers1

0

One more suggestion the code which you have shared in your question you can put that in an async task and from there you van update your list by calling adapter.notifyDataSetChanged(). In this way your app will not stuck and your user can do other task while you load list.

Please note: 2 async tasks can not run in parallel.

Ankit
  • 1,916
  • 2
  • 20
  • 33