[Android] Get device directories with current context
Geoffrey Métais
git at videolan.org
Wed Feb 14 17:36:18 CET 2018
vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 12 12:11:45 2018 +0100| [f956b4869becac2cf2e4906d496b821bc47f9111] | committer: Geoffrey Métais
Get device directories with current context
(cherry picked from commit 500289eba36efb994cbc2fe6c718d93c0d234c95)
> https://code.videolan.org/videolan/vlc-android/commit/f956b4869becac2cf2e4906d496b821bc47f9111
---
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