Mobile Hotspot Name and Password
Asked Answered
E

1

0

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.

Enclitic answered 6/2, 2019 at 12:33 Comment(0)
L
2

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
Lattermost answered 6/8, 2019 at 0:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.