[Android] Get device directories with current context

Geoffrey Métais git at videolan.org
Mon Feb 12 15:02:00 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 12 12:11:45 2018 +0100| [500289eba36efb994cbc2fe6c718d93c0d234c95] | committer: Geoffrey Métais

Get device directories with current context

> https://code.videolan.org/videolan/vlc-android/commit/500289eba36efb994cbc2fe6c718d93c0d234c95
---

 vlc-android/src/org/videolan/vlc/MediaParsingService.java    | 2 +-
 vlc-android/src/org/videolan/vlc/util/AndroidDevices.java    | 6 +++++-
 vlc-android/src/org/videolan/vlc/util/CustomDirectories.java | 7 ++++++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 439ff1315..de6dcc891 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -217,7 +217,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                     shouldInit |= initCode == Medialibrary.ML_INIT_DB_RESET;
                     if (initCode != Medialibrary.ML_INIT_FAILED) {
                         final List<String> devices = new ArrayList<>();
-                        Collections.addAll(devices, AndroidDevices.getMediaDirectories());
+                        Collections.addAll(devices, AndroidDevices.getMediaDirectories(context));
                         final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
                         for (final String device : devices) {
                             final boolean isMainStorage = TextUtils.equals(device, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
diff --git a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
index 3e42807cd..f527916c4 100644
--- a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
+++ b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
@@ -169,10 +169,14 @@ public class AndroidDevices {
     }
 
     public static String[] getMediaDirectories() {
+        return getMediaDirectories(VLCApplication.getAppContext());
+    }
+
+    public static String[] getMediaDirectories(Context ctx) {
         final List<String> list = new ArrayList<>();
         list.add(EXTERNAL_PUBLIC_DIRECTORY);
         list.addAll(getExternalStorageDirectories());
-        list.addAll(Arrays.asList(CustomDirectories.getCustomDirectories()));
+        list.addAll(Arrays.asList(CustomDirectories.getCustomDirectories(ctx)));
         return list.toArray(new String[list.size()]);
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java b/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
index 1575f4fee..1d290b7e8 100644
--- a/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
+++ b/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
@@ -20,6 +20,7 @@
 
 package org.videolan.vlc.util;
 
+import android.content.Context;
 import android.content.SharedPreferences;
 import android.preference.PreferenceManager;
 
@@ -74,7 +75,11 @@ public class CustomDirectories {
     }
 
     public static String[] getCustomDirectories() {
-        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+        return getCustomDirectories(VLCApplication.getAppContext());
+    }
+
+    public static String[] getCustomDirectories(Context ctx) {
+        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
         final String custom_paths = preferences.getString("custom_paths", "");
         if (custom_paths.equals(""))
             return new String[0];



More information about the Android mailing list