Android Check Internet Connectivity edit

Check if device has internet connectivity

Add the required network permissions to the application manifest file:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
/**
 * If network connectivity is available, will return true
 *
 * @param context the current context
 * @return boolean true if a network connection is available
 */
public static boolean isNetworkAvailable(Context context) {

ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { Log.d(“NetworkCheck”, “isNetworkAvailable: No”); return false; }

// get network info for all of the data interfaces (e.g. WiFi, 3G, LTE, etc.) NetworkInfo[] info = connectivity.getAllNetworkInfo();

// make sure that there is at least one interface to test against if (info != null) { // iterate through the interfaces for (int i = 0; i < info.length; i++) { // check this interface for a connected state if (info[i].getState() == NetworkInfo.State.CONNECTED) { Log.d(“NetworkCheck”, “isNetworkAvailable: Yes”); return true; } } } return false;

}

Table Of Contents
39 ACRA
64 Menu
102 Check Internet Connectivity
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close