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

不打扰是莪最后的温柔 提交于 2020-01-01 07:03:11

问题


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!



来源:https://stackoverflow.com/questions/40418810/android-7-0-not-able-to-get-list-of-files-under-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!