【问题标题】:Mobile Hotspot Name and Password移动热点名称和密码
【发布时间】:2019-02-06 12:33:49
【问题描述】:

我必须在 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。我需要移动热点的名称。

【问题讨论】:

    标签: mobile get hotspot


    【解决方案1】:

    您可以使用反射在 API

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多