如何使用Android Studio在android 10中的目录中列出所有文件? [英] How do I list all file in a directory in android 10 using Android Studio?

查看:853
本文介绍了如何使用Android Studio在android 10中的目录中列出所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的代码使用:

String DirectoryPath = "/storage/emulated/0";
File f = new File(DirectoryPath);
File[] file = f.listFiles();

问题在于,该数组对于所有外部内容都为空白:

The problem is that the array comes up as blank for anything outside:

/storage/emulated/0/Android/data/com.example.myProgram

从我在网上阅读的内容来看,这不再适用于android 10+.那么,我将如何列出某个目录中的所有文件? (将文件浏览器作为应用程序的一部分)

From what I read online this no longer works with android 10+. So how would I list all files in a certain directory? (Making a file explorer as part of an App)

推荐答案

只需将这行代码添加到应用程序标记中的清单中即可.

Just add this line of code to your manifest in the application tag.

android:requestLegacyExternalStorage ="true"

android: requestLegacyExternalStorage= "true"

这篇关于如何使用Android Studio在android 10中的目录中列出所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆