开发者

android emulator sd card

I want to read all the music files from the sd card but I tried to put the file in several places on the SD card and the program still doesn't find the music on the card. Anyone any s开发者_如何学Cuggestions? Where exactly to put the files?


I was just doing that last night :).

In android, the sdcard is mounted on '/sdcard'. I don't have the code here, but it was something like this.

public List<String> getMp3Files() {
    File sdcard = new File("/sdcard");
    return getMp3Files(sdcard);
}

private List<String> getMp3Files(File directory) {
    List<String> mp3files = new ArrayList<String>();

    File[] files = directory.listFiles();
    if(files == null) {
        return Collections.EMPTY_LIST;
    }

    for( File file : files) {
        if( file.isFile() && file.getName().toLowerCase().endsWith(".mp3")) {
            mp3files.add(file.getAbsolutePath());
        } else if ( file.isDirectory()) {
            mp3files.addAll(getMp3Files(file));
        }
    }

    return mp3files;
}

it's not optimized AT ALL for mobiles, but it works. And be careful that if you run this code starting on the root folder, it will end up in a infinite loop of folders! (you can always try :D).


Maybe this could help you

http://blog.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜