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

2019-04-01 18:57发布

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();

3条回答
姐就是有狂的资本
2楼-- · 2019-04-01 19:05

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()
查看更多
Luminary・发光体
3楼-- · 2019-04-01 19:16

Use Environment.getRootDirectory() replace it!

查看更多
疯言疯语
4楼-- · 2019-04-01 19:31

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.

查看更多
登录 后发表回答