简体   繁体   English

Android无法访问外部存储

[英]Android unable to access external storage

I have this code: 我有以下代码:

File rootsd = Environment.getExternalStorageDirectory();
File[] imagelist = rootsd.listFiles(new FilenameFilter(){
public boolean accept(File dir, String name)
{
 return ((name.endsWith(".jpg"))||(name.endsWith(".png")));
}
});

And my permission: 我的同意:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Somehow the imagelist is null instead of empty. 图像列表以某种方式为空而不是空。 Can anyone help me. 谁能帮我。 Thanks a lot. 非常感谢。

move rootsd file upto the directory where images are present. 将rootsd文件移至存在图像的目录。 you are just considering /mnt/sdcard path. 您只是在考虑/ mnt / sdcard路径。 point to the directory where images are in, like 指向图像所在的目录,例如

File rootsd = new File(Environment.getExternalStorageDirectory().getPath()
            + File.separator + "imagesdirectory");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM