问题
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;
}
回答1:
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
来源:https://stackoverflow.com/questions/18012557/cant-get-files-with-externalstoragedirectory