is Usable Network - Android Network

Android examples for Network:Network Operation

Description

is Usable Network

Demo Code


//package com.java2s;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;

public class Main {

    public static boolean isUsableNetwork(Context context) {
        boolean retrunVal = true;
        ConnectivityManager cManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netWorkInfo = cManager.getActiveNetworkInfo();
        State netWork = State.DISCONNECTED;
        if (netWorkInfo != null) {
            netWork = netWorkInfo.getState();
        }/*from www  . ja va2 s . c  o  m*/
        if (netWork != State.CONNECTED) {
            retrunVal = false;
        }
        return retrunVal;
    }
}

Related Tutorials