浏览代码

Handle a few more possible external directories before Lollipop

len 8 年之前
父节点
当前提交
582bb3e2ca
共有 1 个文件被更改,包括 13 次插入2 次删除
  1. 13 2
      app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt

+ 13 - 2
app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt

@@ -1,6 +1,7 @@
 package eu.kanade.tachiyomi.util
 
 import android.content.Context
+import android.os.Build
 import android.os.Environment
 import android.support.v4.content.ContextCompat
 import android.support.v4.os.EnvironmentCompat
@@ -73,8 +74,9 @@ object DiskUtil {
     /**
      * Returns the root folders of all the available external storages.
      */
-    fun getExternalStorages(context: Context): List<File> {
-        return ContextCompat.getExternalFilesDirs(context, null)
+    fun getExternalStorages(context: Context): Collection<File> {
+        val directories = mutableSetOf<File>()
+        directories += ContextCompat.getExternalFilesDirs(context, null)
                 .filterNotNull()
                 .mapNotNull {
                     val file = File(it.absolutePath.substringBefore("/Android/"))
@@ -85,6 +87,15 @@ object DiskUtil {
                         null
                     }
                 }
+
+        if (Build.VERSION.SDK_INT < 21) {
+            val extStorages = System.getenv("SECONDARY_STORAGE")
+            if (extStorages != null) {
+                directories += extStorages.split(":").map(::File)
+            }
+        }
+
+        return directories
     }
 
     /**