Android 7.0 Not able to get list of files under “/

2019-04-01 18:38发布

问题:

Before Android 7.0, i was able to get list of files under "/" directory, but on Andorid 7.0 version i am getting null when i try t get list of files from "/" directory.

Below is my code:

File root = new File("/");
File[] files = root.listFiles();

回答1:

From android 7.0 they have applied more restrictions. Now you need to get access for individual directories.

Check this link out for more information.



回答2:

I was facing a similar issue with Android 7.0. Try using "/storage/emulated/0" instead of "/". You should get all the files in your phone storage.

You can also use

Environment.getExternalStorageDirectory().getAbsolutePath()


回答3:

Use Environment.getRootDirectory() replace it!