Can't get files with ExternalStorageDirectory

强颜欢笑 提交于 2020-01-06 01:06:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!