Android: How to connect to an access point using a static IP address?

I tried using the following code to configure the device to use a static ip to connect to an AP without DHCP, but it does not seem to work for any specific access point. The device is still trying to obtain an IP address that it cannot handle, because there is no DHCP.

Settings.System.setString(getContentResolver(), "wifi_static_ip", "192.168.1.99);
Settings.System.setInt(getContentResolver(), "wifi_use_static_ip", 1);

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "SSID";
wc.preSharedKey = "key";
wc.status = WifiConfiguration.Status.ENABLED;
int netId = wifiManager.addNetwork(wc);
wifiManager.enableNetwork(netId, true);

I tried using the method provided by this thread, but it does not work. How to configure a static IP address, netmask, gateway programmatically on Android 3.x or 4.x

+3
source share
1 answer

, .... "wifi_static_ip", "192.168.1.99).... (" ) ... "192.168.1.99". , , IP. ... 255.255.255.0, , , ... ,

0

All Articles