不能与ExternalStorageDirectory获取文件 [英] Can't get files with ExternalStorageDirectory
问题描述
我发现,当我使用code低于它适用于AVD,但是当我打开它的物理设备或Bluestacks - 列表为空,即使该音乐文件SD卡上。任何人都知道是怎么回事?
和,如果你知道如何使它读取内部存储的文件,我将不胜感激,事业为我发现 - 许多手机有大的内存容量和他们不使用SD卡(有些甚至不能)。
这里的code:
静态乌里[]缪里斯;
静态的String [] mFiles = NULL;
公共静态的String [] getMusic(){ 文件音乐= Environment.getExternalStorageDirectory(); //文件ASD =环境。 //的String [] = savedFiles getApplicationContext()的fileList()。 文件[] = musicList music.listFiles(新的FilenameFilter(){ @覆盖
公共布尔接受(文件目录,字符串名称){
// TODO自动生成方法存根
收益率((name.endsWith(MP3)||(name.endsWith(WAV))));
}
}); mFiles =新的String [musicList.length]
的for(int i = 0; I< musicList.length;我++){
mFiles [I] = musicList [I] .getAbsolutePath();
} 返回mFiles;
}
我建议你先找到SD卡的可用空间
阅读本文档可以帮助你
http://developer.android.com/reference/android/os/StatFs.html
块引用>I found that when I use code below it works on AVD, but when I open it on physical device or Bluestacks - the list is empty, even though that music files are on sdcard. Anyone knows what is going on?
And, if You know how to make it read files from internal memory I would be grateful, cause as I found out - many phones have big memory capacity and they don't use sd cards (some of them even can't).
Here's the code:
static Uri[] mUris; static String[] mFiles = null; public static String[] getMusic(){ File music = Environment.getExternalStorageDirectory(); // File asd = Environment. // String[] savedFiles = getApplicationContext().fileList(); File[] musicList = music.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { // TODO Auto-generated method stub return ((name.endsWith(".mp3")||(name.endsWith(".wav")))); } }); mFiles = new String[musicList.length]; for(int i=0; i<musicList.length;i++) { mFiles[i]=musicList[i].getAbsolutePath(); } return mFiles; }
解决方案I would suggest you to first find the free space available in sd card read this doc may help you http://developer.android.com/reference/android/os/StatFs.html
这篇关于不能与ExternalStorageDirectory获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!