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?

4

1 回答 1

0

另一个建议是您在问题中共享的代码,您可以将其放入一个async task并从那里您可以通过调用更新您的列表adapter.notifyDataSetChanged()。这样,您的应用程序就不会卡住,并且您的用户可以在加载列表时执行其他任务。

请注意:2个async tasks不能并行运行

于 2013-05-19T11:29:37.193 回答