How can I get a list of all mp3 files on an SD card regardless of the directory in android?

Using the open source MusicDroid code with the following code that I found while searching for this problem, I can only get mp3 files that are in the root directory / sdcard /

File home = Environment.getExternalStorageDirectory();

if (home.listFiles( new Mp3Filter()).length > 0) {
    for (File file : home.listFiles( new Mp3Filter())) {
        songs.add(file.getAbsolutePath());
    }
    ArrayAdapter<String> songList = new ArrayAdapter<String>
          (this,R.layout.song_item,songs);
    setListAdapter(songList);
}

How can I get all mp3 files from the card (in any directory) to the list of 'songs'?

+3
source share
1 answer

Depending on what you want, you can simply request media storage. Android scans the SD card every time it is re-mounted, so MediaStore.Audio must have all the necessary information.

+1
source

Source: https://habr.com/ru/post/1753987/


All Articles