Here you can find the source of isNetworkReady(Context context)
Parameter | Description |
---|---|
context | a parameter |
public static boolean isNetworkReady(Context context)
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /**// w w w. j av a2 s .c o m * Check the network interface (system-level) connectivity * ATTENTION: permissions must be set in manifest.xml * @param context * @return */ public static boolean isNetworkReady(Context context) { boolean status = false; try { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getNetworkInfo(0); if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { status = true; } else { netInfo = cm.getNetworkInfo(1); if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) status = true; } } catch (Exception e) { //e.printStackTrace(); return false; } return status; } }