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

耗尽温柔 提交于 2019-12-28 10:05:17

问题


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.


回答1:


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>



回答2:


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.




回答3:


Have you tried using WifiInfo.getSSID() ?

http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getSSID%28%29



来源:https://stackoverflow.com/questions/7599569/how-to-get-my-wifi-hotspot-ssid-in-my-current-android-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!