[Android] Init network status at monitor registration

Geoffrey Métais git at videolan.org
Wed Sep 20 11:22:09 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Sep 20 10:49:37 2017 +0200| [19d1e2ca37c31ae32b42ed5e126f4bfb049c7167] | committer: Geoffrey Métais

Init network status at monitor registration

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

 vlc-android/src/org/videolan/vlc/ExternalMonitor.java | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/ExternalMonitor.java b/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
index 3b28795c5..79872293e 100644
--- a/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
+++ b/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
@@ -51,8 +51,8 @@ import java.util.List;
 
 public class ExternalMonitor extends BroadcastReceiver {
     public final static String TAG = "VLC/ExternalMonitor";
-    private static volatile boolean connected = true;
-    private static volatile boolean mobile = true;
+    private static volatile boolean connected = false;
+    private static volatile boolean mobile = false;
     private static volatile boolean vpn = false;
     private static final ExternalMonitor instance = new ExternalMonitor();
     private static final List<NetworkObserver> networkObservers = new LinkedList<>();
@@ -70,6 +70,21 @@ public class ExternalMonitor extends BroadcastReceiver {
         filter.addAction(Intent.ACTION_MEDIA_EJECT);
         filter.addDataScheme("file");
         ctx.registerReceiver(instance, filter);
+        instance.init();
+    }
+
+    private void init() {
+        if (cm == null)
+            cm = (ConnectivityManager) VLCApplication.getAppContext().getSystemService(
+                    Context.CONNECTIVITY_SERVICE);
+        if (cm == null)
+            return;
+        final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
+        if (networkInfo == null)
+            return;
+        connected = networkInfo.isConnected();
+        mobile = networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
+        vpn = updateVPNStatus();
     }
 
     static void unregister(Context ctx) {



More information about the Android mailing list