如何在Android Oreo中获取Hotspot SSID(主机名)?

时间:2018-08-01 07:29:27

标签: android android-wifi android-8.0-oreo android-8.1-oreo personal-hotspot

我正在使用以下代码在Android Oreo下获取热点SSID

WifiManager mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

WifiConfiguration netConfig = new WifiConfiguration();

try{
    Method setWifiApMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
    boolean apstatus=(Boolean) setWifiApMethod.invoke(mWifiManager, netConfig,true);
    Method isWifiApEnabledmethod = mWifiManager.getClass().getMethod("isWifiApEnabled");

    while(!(Boolean)isWifiApEnabledmethod.invoke(mWifiManager))
            {}

    Method getWifiApStateMethod = mWifiManager.getClass().getMethod("getWifiApState");
    int apstate=(Integer)getWifiApStateMethod.invoke(mWifiManager);
    Method getWifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration");
    netConfig=(WifiConfiguration)getWifiApConfigurationMethod.invoke(mWifiManager);
    Log.e("CLIENT", "\nSSID:"+netConfig.SSID+"\nPassword:"+netConfig.preSharedKey+"\n");
   } catch (Exception e) {
            Log.e(this.getClass().toString(), "", e);
     }

这不适用于 Android 8.0及更高版本

是否有任何方法可以在Android Oreo及更高版本中获取热点SSID(热点名称)

谢谢!!

0 个答案:

没有答案