@RequiresApi(LOLLIPOP) @Override public File[] getExternalMediaDirs() { return mBase.getExternalMediaDirs(); }
@RequiresApi(LOLLIPOP) @Override public File[] getExternalMediaDirs() { return mBase.getExternalMediaDirs(); }
/** * Returns the guessed media paths for this device * * @return array with guessed directories */ private static ArrayList<String> discoverDefaultMediaPaths(Context context) { ArrayList<String> defaultPaths = new ArrayList<>(); // Try to discover media paths using getExternalMediaDirs() on 5.x and newer if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { for (File file : context.getExternalMediaDirs()) { // Seems to happen on some Samsung 5.x devices. :-( if (file == null) continue; String path = file.getAbsolutePath(); int match = path.indexOf("/Android/media/"); // From Environment.DIR_ANDROID + Environment.DIR_MEDIA (both hidden) if (match >= 0) defaultPaths.add(path.substring(0, match)); } } // Fall back to old API and some guessing if nothing was found (yet). if (defaultPaths.size() == 0) { // this should always exist defaultPaths.add(Environment.getExternalStorageDirectory().getAbsolutePath()); // this *may* exist File sdCard = new File("/storage/sdcard1"); if (sdCard.isDirectory()) defaultPaths.add(sdCard.getAbsolutePath()); } return defaultPaths; }
public static File getDefaultMusicDirectory(Context context) { if (DEFAULT_MUSIC_DIR == null) { File[] dirs; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { dirs = context.getExternalMediaDirs(); } else { dirs = ContextCompat.getExternalFilesDirs(context, null); } DEFAULT_MUSIC_DIR = new File(getBestDir(dirs), "music"); if (!DEFAULT_MUSIC_DIR.exists() && !DEFAULT_MUSIC_DIR.mkdirs()) { Log.e(TAG, "Failed to create default dir " + DEFAULT_MUSIC_DIR); // Some devices seem to have screwed up the new media directory API. Go figure. Try again with standard locations if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { dirs = ContextCompat.getExternalFilesDirs(context, null); DEFAULT_MUSIC_DIR = new File(getBestDir(dirs), "music"); if (!DEFAULT_MUSIC_DIR.exists() && !DEFAULT_MUSIC_DIR.mkdirs()) { Log.e(TAG, "Failed to create default dir " + DEFAULT_MUSIC_DIR); } else { Log.w(TAG, "Stupid OEM's messed up media dir API added in 5.0"); } } } } return DEFAULT_MUSIC_DIR; }
dirs = context.getExternalMediaDirs(); } else { dirs = ContextCompat.getExternalFilesDirs(context, null);
if (Build.VERSION.SDK_INT > 20) { File external[] = context.getExternalMediaDirs(); if (external.length > 1) { filePath = external[1].getAbsolutePath();
String externalSd = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { File[] dirs = context.getExternalMediaDirs(); for (File dir : dirs) { if (dir == null || !dir.exists()) {