has Wifi Connection - Android Network

Android examples for Network:Network Connection

Description

has Wifi Connection

Demo Code


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

public class Main {
    public static Boolean hasWifiConnection(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo wifiNetwork = cm/*w  ww.j  a v  a2 s.  c  o m*/
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetwork != null && wifiNetwork.isConnected()) {
            return true;
        }

        return false;
    }
}

Related Tutorials