简体   繁体   中英

Displaying current connected WIFI SSID name

I am displaying current connected WiFi SSID name in my android app..it displaying current connected WiFi SSID name.

problem is printing "rakesh" like this Its printing along with this symbol" " can anyone help me

   ConnectivityManager connectivityManager = (ConnectivityManager) 
    context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if(wifiInfo.isConnected() == true){
        WifiInfo localInfo = wifiManager.getConnectionInfo();
        Details = "Connected to " + localInfo.getSSID();

    }else{
        Details = "Not Connected";
    }

try this

WifiManager wifiManager = (WifiManager) getSystemService (Context.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo ();
String ssid  = info.getSSID();

尝试使用:android.net.wifi.WifiInfo.getSSID

Try this.

 WifiManager wifiMgr = (WifiManager) getContext().getSystemService(context.WIFI_SERVICE);

    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    String ssid = wifiInfo.getSSID();

Add Following Permission on your Manifest.

 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

A little late answer but from the documentation of WifiInfo.getSSID() :

If the SSID can be decoded as UTF-8, it will be returned surrounded by double quotation marks

which seems to be the problem in your case. If you don't need the " characters just remove them from the String.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM