AKSHAY TAMBE
AKSHAY TAMBE

Reputation: 1

Mobile Hotspot Name and Password

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.

Upvotes: 0

Views: 1622

Answers (1)

Adeel Zafar
Adeel Zafar

Reputation: 371

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

Upvotes: 2

Related Questions