3

I tried to use the following code to set the device to use static ip to join an AP without DHCP, but it doesn't seem to work for any particular AP. The device still tries to obtain an IP address which it fails to since lack of 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 to use the method this thread provided, but it doesn't work. How to configue a static IP address, netmask, gateway programmatically on Android 3.x or 4.x

Community
  • 1
  • 1
Leon Hu
  • 137
  • 1
  • 1
  • 5

1 Answers1

0

Well at first look it looks like problem is with your Code.... "wifi_static_ip", "192.168.1.99).... you are missing (") here...you have to write it like this "192.168.1.99". If not then double check it if you dont have an I.P conflict.... And what is the Subnet mask of your network... if it is 255.255.255.0 then no need to mention but if it is changed then you have to mention that... hope it Helps

Hassan
  • 56
  • 2