Force Android to Use Wifi network with no internet

前端 未结 5 903
猫巷女王i
猫巷女王i 2020-12-24 06:23

I am building an android app that needs to communicate over a WiFi network that will not have any internet access. The problem is that even when the WiFi is connected androi

5条回答
  •  离开以前
    2020-12-24 06:36

    Could you try and set the global setting captive_portal_detection_enabled to 0 (false).

    What's actually happening is that by default, everytime you connect to a wifi, the FW will test against a server (typically google) to see if it's a captive wifi (needs login). So if your wifi is not connected to google, this check will fail. After that, the device knows that wifi has no internet connection and simply will not autoconnect to it.

    Setting this setting to 0, will avoid this check.

    Programatically: Settings.Global.putInt(getContentResolver(), Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED, 0);

    Edit: You may need to use the string "captive_portal_detection_enabled" directly, instead of the constant that's not visible depending on Android version.

提交回复
热议问题