is WiFi Connected using NetworkInfo - Android android.net.wifi

Android examples for android.net.wifi:Wifi State

Description

is WiFi Connected using NetworkInfo

Demo Code

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import java.util.List;

public class Main{

    public static boolean isWiFiConnected(Context c) {
        ConnectivityManager cm = (ConnectivityManager) c
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        boolean state = wifi.isConnected();
        //        Log.i(LOG_TAG, String.format("WiFi State:%b", state));
        return state;
    }/*ww w  .  ja v a  2  s .com*/

}

Related Tutorials