Android Captive Portal 设置笔记
1. 背景
Android 系统通过“captive portal 检测”判断 Wi-Fi 网络是否有互联网连接:
-
系统默认访问:
connectivitycheck.android.com - 如果访问失败,Wi-Fi 图标上会显示
!,提示“可能无法访问互联网”。 - 在国内或被屏蔽网络环境中,默认检测服务器不可访问,会导致误判。
2. 检测服务器修改方法
2.1 命令(需要 root 权限)
在 终端模拟器 或 ADB shell 执行:
su
settings put global captive_portal_server <SERVER>
settings put global captive_portal_http_url <HTTP_URL>
settings put global captive_portal_https_url <HTTPS_URL>
settings put global captive_portal_mode 1
说明:
captive_portal_server:检测服务器域名captive_portal_http_url/captive_portal_https_url:访问的 URLcaptive_portal_mode:0:关闭检测1:开启检测(默认)
3. 中国大陆推荐设置
稳定且兼容 Android:
su
settings put global captive_portal_server connect.rom.miui.com
settings put global captive_portal_http_url http://connect.rom.miui.com/generate_204
settings put global captive_portal_https_url https://connect.rom.miui.com/generate_204
settings put global captive_portal_mode 1
说明:
- 服务器
connect.rom.miui.com在国内访问稳定 - 返回 HTTP 204 状态码,系统不会误判网络
- 配置在刷机或脏刷后依然生效
可选
- 使用
g.cn(Google.cn 简写)也可用,但可能不够稳定:
settings put global captive_portal_server g.cn
4. 国外(全球通用)推荐设置
如果网络可以访问 Google 官方服务器,可使用:
su
settings put global captive_portal_server connectivitycheck.gstatic.com
settings put global captive_portal_http_url http://connectivitycheck.gstatic.com/generate_204
settings put global captive_portal_https_url https://connectivitycheck.gstatic.com/generate_204
settings put global captive_portal_mode 1
说明:
- 适用于大多数国际网络环境
- 返回 HTTP 204,兼容 Android 系统检测
5. 验证是否生效
执行:
adb shell settings get global captive_portal_server
adb shell settings get global captive_portal_http_url
adb shell settings get global captive_portal_https_url
adb shell settings get global captive_portal_mode
输出应为你设置的值,如:
connect.rom.miui.com
http://connect.rom.miui.com/generate_204
https://connect.rom.miui.com/generate_204
1
6. 注意事项
-
如果没有 root,
su命令不可用,可尝试通过 adb shell 修改:adb shell settings put global captive_portal_server <SERVER>但某些设备可能权限不足,需要 root 才能生效。
- 修改服务器不会影响实际网络访问,只改变系统检测网络可用性的机制。
- 使用国内 204 地址在国内网络环境下最稳定;国外网络可用 Google 官方服务器。