Add method getWifiApState() and isWifiApEnabled()

It's used to get current state of wifi access point.
This commit is contained in:
Adeel Zafar 2019-05-28 16:59:34 +05:00
parent 8eff3c5d84
commit bd328b5d1d

View File

@ -45,6 +45,28 @@ public class WifiHotspotManager {
}
}
public WIFI_AP_STATE_ENUMS getWifiApState() {
try {
Method method = wifiManager.getClass().getMethod("getWifiApState");
int tmp = ((Integer) method.invoke(wifiManager));
// Fix for Android 4
if (tmp >= 10) {
tmp = tmp - 10;
}
return WIFI_AP_STATE_ENUMS.class.getEnumConstants()[tmp];
} catch (Exception e) {
Log.e(this.getClass().toString(), "", e);
return WIFI_AP_STATE_ENUMS.WIFI_AP_STATE_FAILED;
}
}
public boolean isWifiApEnabled() {
return getWifiApState() == WIFI_AP_STATE_ENUMS.WIFI_AP_STATE_ENABLED;
}
public WifiConfiguration getWifiApConfiguration() {
try {
Method method = wifiManager.getClass().getMethod("getWifiApConfiguration");