简体   繁体   中英

How to get my wifi hotspot ssid in my current android system

I have a problem that I couldn't find my wifi hotspot ssid in my Android system.
I found many information from google, but nothing helpful.
Please help me to solve it.

You can use WifiManager and WifiInfo for getting Wifi SSID

   WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
   WifiInfo wifiInfo = wifiManager.getConnectionInfo();
   Log.d("wifiInfo", wifiInfo.toString());
   Log.d("SSID",wifiInfo.getSSID());

Also add Permission in your Manifest file.

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

Here: http://www.androidjavadoc.com/2.3/android/net/wifi/WifiManager.html is the full documentation on the WifiManager.

Note that some of the methods are only available through inspection, as is the method you need getWifiApConfiguration .

WifiManager wifimanager = (WifiManager) getSystemService(WIFI_SERVICE);
Method[] methods = wifimanager.getClass().getDeclaredMethods();
for (Method m: methods) {           
    if (m.getName().equals("getWifiApConfiguration")) {
        WifiConfiguration config = (WifiConfiguration)m.invoke(wifimanager);

            // here, the "config" variable holds the info, your SSID is in
            // config.SSID
    }
}

O, and because this stuff is marked hidden, it can change or be completely removed in any future version of Android. So, don't rely on it too much on "official" apps, unless you make that very clear.

Check via NetworkInfo for wifi-type if it is connected. And then use wifiinfo getSSid(). You might want to remove double slashes from returnd SSID

https://play.google.com/store/apps/details?id=com.connect.freewifi

You should check out this application and developer api from http://developer.android.com/reference/android/net/wifi/WifiInfo.html

It will help you with your task.

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