Android Question how to read or get presharekey(wpa,wpa2) of hotspot and save(backup) before set new key

boon2

Member
Licensed User
Longtime User
try{

Method setWifiApMethod = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
boolean apstatus=(Boolean) setWifiApMethod.invoke(wifiManager, netConfig,true);

Method isWifiApEnabledmethod = wifiManager.getClass().getMethod("isWifiApEnabled");
while(!(Boolean)isWifiApEnabledmethod.invoke(wifiManager)){};

Method getWifiApStateMethod = wifiManager.getClass().getMethod("getWifiApState");
int apstate=(Integer)getWifiApStateMethod.invoke(wifiManager);

Method getWifiApConfigurationMethod = wifiManager.getClass().getMethod("getWifiApConfiguration");
netConfig=(WifiConfiguration)getWifiApConfigurationMethod.invoke(wifiManager);

Log.i("Writing HotspotData", "\nSSID:"+netConfig.SSID+"\nPassword:"+netConfig.preSharedKey+"\n");

} catch (Exception e) {
e.printStackTrace();
}
 
Upvote 0
Top