gpt4 book ai didi

Android 4.4 文件列表问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:37:37 24 4
gpt4 key购买 nike

我试图获取 /sdcard/ 文件夹中的文件,但它抛出 NullPointerException

然后我尝试在它返回的/路径中获取文件夹

40
factory
usbdisk
sdcard
storage
config
cache
acct
vendor
d
etc
mnt
ueventd.tuna.rc
ueventd.rc
ueventd.goldfish.rc
system
sys
sepolicy
seapp_contexts
sbin
res
... and others

当我在 4.3 项目中执行此操作时,效果很好!

更新

4.4 中的代码不起作用

File file = Environment.getExternalStorageDirectory();
File[] files = file.listFiles();
Debugger.info(files.length); // NullPointerExcepton
for(File f : files){
Debugger.info(f.getName());
}

最佳答案

Android Developers站点状态(在 KitKat 的重要行为变化中)

If your app reads from external storage...

Your app can not read shared files on the external storage when running on Android 4.4, unless your app has the READ_EXTERNAL_STORAGE permission. That is, files within the directory returned by getExternalStoragePublicDirectory() are no longer accessible without the permission. However, if you need to access only your app-specific directories, provided by getExternalFilesDir(), then you do not need the READ_EXTERNAL_STORAGE permission.

因此请确保您给予上述许可。此外,如果您使用的设备带有多个 SD 卡,您可以在 this issue 中运行.

关于Android 4.4 文件列表问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20221307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com