[Android] [PATCH 1/3] Util method to check for LAN connection

Geoffrey Métais geoffrey.metais at gmail.com
Tue Feb 10 17:12:21 CET 2015


---
 .../src/org/videolan/vlc/util/AndroidDevices.java        | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
index 7272e21..81a8191 100644
--- a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
+++ b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
@@ -34,6 +34,8 @@ import org.videolan.libvlc.LibVlcUtil;
 import org.videolan.vlc.VLCApplication;
 
 import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
 import android.os.Build.VERSION;
 import android.os.Build.VERSION_CODES;
 import android.os.Environment;
@@ -167,4 +169,18 @@ public class AndroidDevices {
         }
         return 0;
     }
+
+    public static boolean hasLANConnection(){
+        boolean networkEnabled = false;
+        ConnectivityManager connectivity = (ConnectivityManager)(VLCApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE));
+        if (connectivity != null) {
+            NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
+            if (networkInfo != null && networkInfo.isConnected() &&
+                    (networkInfo.getType() != ConnectivityManager.TYPE_MOBILE)) {
+                networkEnabled = true;
+            }
+        }
+        return networkEnabled;
+
+    }
 }
-- 
2.1.0



More information about the Android mailing list