0

I want to search for all my songs on my removeable SDCard but it seems like I only get ringtones and some downloaded music from my internal storage. I have Android 6.0 (Huawei).

private static ArrayList<String> scanDeviceForSongs_All(File startingFolder ){

        ArrayList<String> ret = new ArrayList<String>();

        if( startingFolder == null )
            return ret;

        if( startingFolder.list() == null )
            return ret;

        for( File fileEntry : startingFolder.listFiles() ) {

            if( fileEntry.isDirectory() ) {
                //recursively add all sub directories
                ret.addAll( scanDeviceForSongs_All( fileEntry ) );
            } else {
                final String path = fileEntry.getAbsolutePath();
                if( isAudio( path ) )
                    ret.add( path );
            }
        }

        return ret;
    }

public static boolean isAudio( String s ) {

        final String[] supportedFormats = { ".mp3", ".ogg", ".oga", ".wav", ".acc", ".mp4", ".m4a", ".flac", ".3gp", ".mkv" };

        //iterate through formats and end if one was found
        for( String suffix : supportedFormats ) {
            if( s.endsWith( suffix) )
                return true;
        }

        //none were found, either no audio or not supported
        return false;
    }

I call sometime during the startup scanDeviceForSongs_All( Environment.getExternalStorageDirectory() ) in a Fragment. It works, I do get something, though it is the internal storage that is being analyzed and not my SD-Card which has basically all of my songs.

How do I get the path for my SDCard?

Davlog
  • 2,162
  • 8
  • 36
  • 60
  • read this answer, http://stackoverflow.com/a/38749994/794088 – petey Jan 13 '17 at 20:15
  • 1
    "How do I get the path for my SDCard?" -- you don't. You do not have direct filesystem access to arbitrary locations on [removable storage](https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html) on Android 4.4+. Instead, query the `MediaStore` to find all relevant media. This will be **much** faster than you scanning a filesystem yourself, and it will cover removable storage as well as [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). – CommonsWare Jan 13 '17 at 20:15
  • Alright guys, thanks. – Davlog Jan 13 '17 at 20:18

0 Answers0