I want to resolve next problem. My device is in AP mode (portable WiFi hotspot). It has to show IP of it
. Another device connect to this one by using known IP. It have to work without any WiFi-routers, just device to device.
How to get the IP address if the radio is already running in AP mode? I have some code about AP:
public boolean setWifiApEnabled(WifiConfiguration config, boolean enabled) {
try {
if (enabled) { // disable WiFi in any case
mWifiManager.setWifiEnabled(false);
}
Method method = mWifiManager.getClass().getMethod(
"setWifiApEnabled", WifiConfiguration.class,
boolean.class);
return (Boolean) method.invoke(mWifiManager, config, enabled);
} catch (Exception e) {
//Log.e(TAG, "", e);
return false;
}
}
public int getWifiApState() {
try {
Method method = mWifiManager.getClass().getMethod(
"getWifiApState");
return (Integer) method.invoke(mWifiManager);
} catch (Exception e) {
//Log.e(TAG, "", e);
return WIFI_AP_STATE_FAILED;
}
}
public static boolean IsWifiApEnabled(Context context){
boolean isWifiAPEnabled = false;
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
for(Method method: wmMethods){
if(method.getName().equals("isWifiApEnabled")) {
try {
isWifiAPEnabled = (Boolean) method.invoke(wifi);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
return isWifiAPEnabled;
}
}
Maybe there is some trick to get IP of it? Please help me. Thanks.