get Wifi Ssid - Android Wifi

Android examples for Wifi:Wifi SSID

Description

get Wifi Ssid

Demo Code


//package com.java2s;
import android.content.Context;

import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

public class Main {
    public static String getWifiSsid(Context context) {
        String wifi_name = "";
        try {//from w w w . ja v a2  s . c o  m
            WifiManager wifiMgr = (WifiManager) context
                    .getSystemService(Context.WIFI_SERVICE);
            // int wifiState = wifiMgr.getWifiState();
            WifiInfo info = wifiMgr.getConnectionInfo();
            wifi_name = info != null ? info.getSSID() : "";
            wifi_name = wifi_name.replace("\"", "");
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            wifi_name = "";
        }

        return wifi_name;
    }
}

Related Tutorials