移动热点名称和密码

问题描述 投票:0回答:1

我必须在 android studio 中以编程方式获取移动热点的名称和密码。我该怎么做?

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
  
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Toast.makeText(this,"SSID:"+wifiInfo.getSSID(),Toast.LENGTH_LONG).show();

此代码为我提供了我所连接的 wifi 的 SSID。我需要我的移动热点的名称。

android wifimanager hotspot
1个回答
2
投票

您可以在API中获取您热点的wifi配置<26 using reflection. Its not the recommended way but if you need it bad, then here it is.

private WifiConfiguration currentConfig;
  private WifiConfiguration getWifiApConfiguration() {  
    try {   
      Method method = wifiManager.getClass().getMethod("getWifiApConfiguration");   
      return (WifiConfiguration) method.invoke(wifiManager);    
    } catch (Exception e) { 
      Log.e(this.getClass().toString(), "", e); 
      return null;  
    }   
  }

然后您可以使用 WifiConfiguration 对象来获取其详细信息:

currentConfig.SSID
currentConfig.preSharedKey
© www.soinside.com 2019 - 2024. All rights reserved.