[Android] Fix external storage discovery with medialibrary

Geoffrey Métais git at videolan.org
Thu Apr 6 11:59:25 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr  6 11:56:30 2017 +0200| [e91b1ad09ed0467d150d6c915bcbbe3747c10b70] | committer: Geoffrey Métais

Fix external storage discovery with medialibrary

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

 vlc-android/src/org/videolan/vlc/gui/DialogActivity.java   |  3 ++-
 .../videolan/vlc/gui/dialogs/ExternalStorageDialog.java    | 14 ++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java b/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
index bc5e529..1aac7a2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
@@ -65,8 +65,9 @@ public class DialogActivity extends BaseActivity {
 
     private void setupStorageDialog() {
         ExternalStorageDialog dialog = new ExternalStorageDialog();
-        Bundle b = new Bundle(1);
+        Bundle b = new Bundle(2);
         b.putString(MediaParsingService.EXTRA_PATH, getIntent().getStringExtra(MediaParsingService.EXTRA_PATH));
+        b.putString(MediaParsingService.EXTRA_UUID, getIntent().getStringExtra(MediaParsingService.EXTRA_UUID));
         dialog.setArguments(b);
         dialog.show(getSupportFragmentManager(), "fragment_storage");
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/ExternalStorageDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/ExternalStorageDialog.java
index 12781ef..16b551a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/ExternalStorageDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/ExternalStorageDialog.java
@@ -1,8 +1,10 @@
 package org.videolan.vlc.gui.dialogs;
 
+import android.annotation.TargetApi;
 import android.app.Dialog;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.os.Build;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.v4.content.ContextCompat;
@@ -10,6 +12,7 @@ import android.support.v4.view.ViewCompat;
 import android.support.v7.app.AlertDialog;
 import android.support.v7.app.AppCompatDialogFragment;
 
+import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.MediaParsingService;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
@@ -18,21 +21,24 @@ import org.videolan.vlc.util.FileUtils;
 
 public class ExternalStorageDialog extends AppCompatDialogFragment {
 
+    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
         ViewCompat.setBackground(getActivity().getWindow().getDecorView(),
                 ContextCompat.getDrawable(getActivity(), android.R.drawable.screen_background_dark_transparent));
         final String path = getArguments().getString(MediaParsingService.EXTRA_PATH);
-        final String name = FileUtils.getFileNameFromPath(path);
+        final String uuid = AndroidUtil.isHoneycombMr1OrLater ?
+                getArguments().getString(MediaParsingService.EXTRA_UUID, FileUtils.getFileNameFromPath(path))
+                : FileUtils.getFileNameFromPath(path);
         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-        final String message = String.format(VLCApplication.getAppResources().getString(R.string.ml_external_storage_msg), name);
+        final String message = String.format(VLCApplication.getAppResources().getString(R.string.ml_external_storage_msg), uuid);
         builder.setTitle(R.string.ml_external_storage_title)
                 .setMessage(message)
                 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
                         Intent serviceInent = new Intent(MediaParsingService.ACTION_DISCOVER_DEVICE, null, getActivity(), MediaParsingService.class)
                             .putExtra(MediaParsingService.EXTRA_PATH, path)
-                            .putExtra(MediaParsingService.EXTRA_UUID, name);
+                            .putExtra(MediaParsingService.EXTRA_UUID, uuid);
                         if (getActivity() != null) {
                             getActivity().startService(serviceInent);
                             getActivity().finish();
@@ -43,7 +49,7 @@ public class ExternalStorageDialog extends AppCompatDialogFragment {
                     public void onClick(DialogInterface dialog, int id) {
                         PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext())
                                 .edit()
-                                .putBoolean("ignore_"+ name, true)
+                                .putBoolean("ignore_"+ uuid, true)
                                 .apply();
                         if (getActivity() != null)
                             getActivity().finish();



More information about the Android mailing list