简体   繁体   中英

Android: How to connect to an Access Point using static IP?

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

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 IP 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM