get Wifi Name - Android Wifi

Android examples for Wifi:Wifi Connection

Description

get Wifi Name

Demo Code

//  Copyright (c) 2014 Texas Instruments. All rights reserved.
//package com.java2s;
import android.content.Context;

import android.net.wifi.WifiManager;

public class Main {
    public static String getWifiName(Context context) {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        String wifiName = wifiManager.getConnectionInfo().getSSID();
        if (wifiName != null) {
            if (!wifiName.contains("unknown ssid") && wifiName.length() > 2) {
                if (wifiName.startsWith("\"") && wifiName.endsWith("\""))
                    wifiName = wifiName.subSequence(1,
                            wifiName.length() - 1).toString();
                return wifiName;
            } else {
                return "";
            }//from   w w  w .  ja v a  2 s .co  m
        } else {
            return "";
        }
    }
}

Related Tutorials