[Android] DirectoryView: detect new storage devices in realtime
Ludovic Fauvet
git at videolan.org
Thu Nov 22 15:23:21 CET 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Thu Nov 22 15:22:17 2012 +0100| [aceb97d2cbb9c63ae9b3d5bc3f359cead79a3eea] | committer: Ludovic Fauvet
DirectoryView: detect new storage devices in realtime
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=aceb97d2cbb9c63ae9b3d5bc3f359cead79a3eea
---
.../videolan/vlc/gui/DirectoryViewFragment.java | 31 ++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index da75b8f..64ea1dd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -33,6 +33,10 @@ import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.interfaces.ISortable;
import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -61,6 +65,14 @@ public class DirectoryViewFragment extends SherlockListFragment implements ISort
super.onCreate(savedInstanceState);
mDirectoryAdapter = new DirectoryAdapter();
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
+ filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
+ filter.addAction(Intent.ACTION_MEDIA_REMOVED);
+ filter.addAction(Intent.ACTION_MEDIA_EJECT);
+ filter.addDataScheme("file");
+ getActivity().registerReceiver(messageReceiver, filter);
}
@Override
@@ -86,6 +98,11 @@ public class DirectoryViewFragment extends SherlockListFragment implements ISort
}
@Override
+ public void onDestroy() {
+ getActivity().unregisterReceiver(messageReceiver);
+ }
+
+ @Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
int position = ((AdapterContextMenuInfo)menuInfo).position;
@@ -179,4 +196,18 @@ public class DirectoryViewFragment extends SherlockListFragment implements ISort
if (mDirectoryAdapter != null)
mDirectoryAdapter.refresh();
}
+
+ private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+
+ if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_MOUNTED) ||
+ action.equalsIgnoreCase(Intent.ACTION_MEDIA_UNMOUNTED) ||
+ action.equalsIgnoreCase(Intent.ACTION_MEDIA_REMOVED) ||
+ action.equalsIgnoreCase(Intent.ACTION_MEDIA_EJECT)) {
+ refresh();
+ }
+ }
+ };
}
More information about the Android
mailing list