[Android] Util method to check for LAN connection

Geoffrey Métais git at videolan.org
Wed Feb 11 12:13:26 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 10 17:09:41 2015 +0100| [acf46fcb458ec2ae5d40a5deeeec49f441ddc1b3] | committer: Geoffrey Métais

Util method to check for LAN connection

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=acf46fcb458ec2ae5d40a5deeeec49f441ddc1b3
---

 .../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;
+
+    }
 }



More information about the Android mailing list