Mobile Hotspot Name and Password

 ̄綄美尐妖づ 提交于 2020-01-06 06:34:31

问题


I have to get the name and password of my mobile hotspot programmatically in android studio. How do I do it?

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);

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

This code gives me SSID of wifi I am connected to. I need name of my Mobile hotspot.


回答1:


You can get the wificonfiguration of your hotspot in API<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;  
    }   
  }

And then you can use the WifiConfiguration object to get its details:

currentConfig.SSID
currentConfig.preSharedKey


来源:https://stackoverflow.com/questions/54553782/mobile-hotspot-name-and-password

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