【问题标题】:Android: How to connect to an Access Point using static IP?Android:如何使用静态 IP 连接到接入点?
【发布时间】:2012-05-14 12:11:14
【问题描述】:

我尝试使用以下代码将设备设置为使用静态 ip 加入没有 DHCP 的 AP,但它似乎不适用于任何特定的 AP。设备仍然尝试获取 IP 地址,但由于缺少 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);

我尝试使用这个线程提供的方法,但它不起作用。 How to configue a static IP address, netmask, gateway programmatically on Android 3.x or 4.x

【问题讨论】:

    标签: android networking settings android-networking


    【解决方案1】:

    乍一看,问题出在您的代码上......“wifi_static_ip”,“192.168.1.99)......你在这里缺少(”)......你必须这样写“ 192.168.1.99"。如果没有,请仔细检查是否没有 IP 冲突...。您的网络的子网掩码是什么...如果是 255.255.255.0,则无需提及,但如果更改,则必须提及那...希望它有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 2018-06-04
      • 2021-10-10
      • 2020-07-01
      • 2014-09-06
      • 1970-01-01
      • 2017-04-13
      相关资源
      最近更新 更多