我想在我的可移除SDCard 上搜索我的所有歌曲,但似乎我只从内部存储中获取铃声和一些下载的音乐。我有Android 6.0(华为)。
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;
}
我在片段中的启动scanDeviceForSongs_All( Environment.getExternalStorageDirectory() )
期间打电话。它有效,我确实得到了一些东西,虽然它是正在分析的内部存储,而不是我的SD卡,基本上我的所有歌曲。
如何获取SD卡的路径?