简体   繁体   English

显示当前连接的WIFI SSID名称

[英]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. 我在我的Android应用程序中显示当前连接的WiFi SSID名称。它显示了当前连接的WiFi SSID名称。

problem is printing "rakesh" like this Its printing along with this symbol" " can anyone help me 问题是像这样打印“ rakesh”它的打印以及这个符号“”,谁能帮我

   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() : 答案有点晚,但是来自WifiInfo.getSSID()的文档:

If the SSID can be decoded as UTF-8, it will be returned surrounded by double quotation marks 如果可以将SSID解码为UTF-8,则会将其返回,并用双引号引起来

which seems to be the problem in your case. 这似乎是您的问题所在。 If you don't need the " characters just remove them from the String. 如果不需要“”字符,只需将其从字符串中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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