简体   繁体   English

如何在我目前的Android系统中获取我的wifi热点ssid

[英]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. 我有一个问题,我在我的Android系统中找不到我的wifi热点ssid。
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 您可以使用WifiManagerWifiInfo获取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. 还要在Manifest文件中添加Permission。

<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. 这里: http ://www.androidjavadoc.com/2.3/android/net/wifi/WifiManager.html是WifiManager的完整文档。

Note that some of the methods are only available through inspection, as is the method you need getWifiApConfiguration . 请注意,某些方法只能通过检查获得,因为需要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. 哦,因为这些东西被标记为隐藏,它可以在任何未来版本的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. 如果已连接,请通过NetworkInfo检查wifi类型。 And then use wifiinfo getSSid(). 然后使用wifiinfo getSSid()。 You might want to remove double slashes from returnd SSID 您可能希望从returnnd SSID中删除双斜杠

https://play.google.com/store/apps/details?id=com.connect.freewifi 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 您应该从http://developer.android.com/reference/android/net/wifi/WifiInfo.html查看此应用程序和开发人员API。

It will help you with your task. 它将帮助您完成任务。

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

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