简体   繁体   中英

List all the files in a directory and add a filter for a particular mimetype

I have a program that needs the files existing in a particular folder to be listed, this file array then needs to be filtered for video mimetype extensions only so that they can be populated into a list that when a user taps on that path is parsed and played in the VideoView.

I have tried dir.list() but its returning null. The folder whose files am trying to list is the default directory where android places downloads. Here is what i tried:

String store = Environment.DIRECTORY_DOWNLOADS;
java.io.File dir = new java.io.File(store);
File[] mylist=dir.listFiles();
log.d(mylist);

I have the permission to read and write to external storage as defined in the manifest.xml file as

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

log.d(mylist) is printing null while the folder is full of files of all types

I added tis before the main class definition and now i can get to list the files in the ListView thanks to the guy who commented on the post

@RequiresApi(api = Build.VERSION_CODES.Q)

Am debugging on android 10 and i guess new releases come with their own restrictions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM