[Android] Utility methods for checking deivce connextion type

Geoffrey Métais git at videolan.org
Tue Feb 16 15:12:08 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 16 14:55:03 2016 +0100| [8c631ac3f729470d80535a42910ebf819d36a792] | committer: Geoffrey Métais

Utility methods for checking deivce connextion type

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

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

diff --git a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
index 34efd5d..20d2185 100644
--- a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
+++ b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
@@ -218,6 +218,31 @@ public class AndroidDevices {
         return networkEnabled;
     }
 
+    public static boolean hasConnection() {
+        boolean networkEnabled = false;
+        ConnectivityManager connectivity = (ConnectivityManager) (VLCApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE));
+        if (connectivity != null) {
+            NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
+            if (networkInfo != null && networkInfo.isConnected()) {
+                networkEnabled = true;
+            }
+        }
+        return networkEnabled;
+    }
+
+    public static boolean hasMobileConnection() {
+        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;
+    }
+
     public static void setRemoteControlReceiverEnabled(boolean enabled) {
         VLCApplication.getAppContext().getPackageManager().setComponentEnabledSetting(
                 new ComponentName(VLCApplication.getAppContext(), RemoteControlClientReceiver.class),



More information about the Android mailing list