From 2a466fe1bb69c64ea5e897d529a9e21ebbf5cc57 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 27 Mar 2015 17:08:37 -0700 Subject: Add a fallback if the new 5.0 media folder isn't accessible for whatever reason --- src/github/daneren2005/dsub/util/FileUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index 8bd53c0c..b9d7fd1b 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -442,6 +442,24 @@ public class FileUtil { 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); + + for(int i = dirs.length - 1; i >= 0; i--) { + DEFAULT_MUSIC_DIR = new File(dirs[i], "music"); + if(dirs[i] != null) { + break; + } + } + + 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"); + } + } } } -- cgit v1.2.3