get Current Wifi Param From Setting - Android Wifi

Android examples for Wifi:Wifi Connection

Description

get Current Wifi Param From Setting

Demo Code


//package com.java2s;

import android.content.Context;

import android.net.ConnectivityManager;

import android.net.wifi.WifiManager;

public class Main {
    public static String getCurrentWifiParamFromSetting(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {
            return null;
        } else {/*from   ww w .  ja  v a  2 s . com*/
            WifiManager wifiManager = (WifiManager) context
                    .getSystemService(Context.WIFI_SERVICE);
            int wifiNetWorkID = wifiManager.getConnectionInfo()
                    .getNetworkId();
            if (wifiNetWorkID != -1) {
                return String.valueOf(wifiNetWorkID);
            } else {
                return null;
            }
        }
    }
}

Related Tutorials