在使用 Google Pixel 或其他海外品牌的手机,有时可能会遇到连接 Wi-Fi 但无法访问互联网的问题。一种可能的原因是这些手机在检测网络连接状态时使用的 “Captive Portal” 检测机制可能与您所在区域的网络环境不兼容。在这种情况下,您可以使用 Android Debug Bridge(ADB)命令来手动更改这些设置。

Captive Portal 与网络检测

Captive Portal 是一种网络认证机制。当您连接到一个新的 Wi-Fi 网络时,Android 设备会自动访问一个预设的 URL 来检查网络是否需要额外的登录或认证。然而,这个预设的 URL 在某些地区可能是不可达的,导致设备错误地认为网络无法访问互联网。

解决步骤

命令行工具:ADB

首先,确保您已经下载并安装了 Android Studio,或单独下载了 ADB 工具。

开启开发者选项

在进行任何操作之前,请确保您在设备上启用了“开发者选项”并开启了“USB 调试”。

ADB 命令

以下 ADB 命令用于删除和更改 Captive Portal 的检测设置:

adb shell settings delete global captive_portal_https_url
adb shell settings delete global captive_portal_http_url
adb shell settings put global captive_portal_http_url http://connect.rom.miui.com/generate_204
adb shell settings put global captive_portal_https_url https://connect.rom.miui.com/generate_204
  1. 删除现有设置

这两个命令会删除当前设置的 HTTP 和 HTTPS Captive Portal 检测 URL:

adb shell settings delete global captive_portal_https_url
adb shell settings delete global captive_portal_http_url
  1. 添加新设置

这两个命令会设置新的 HTTP 和 HTTPS Captive Portal 检测 URL:

adb shell settings put global captive_portal_http_url http://connect.rom.miui.com/generate_204
adb shell settings put global captive_portal_https_url https://connect.rom.miui.com/generate_204

这里,http://connect.rom.miui.com/generate_204https://connect.rom.miui.com/generate_204 是 miui 使用的,通常在国内表现较好。

注意事项

  1. 在进行上述操作之前,请确保您已经开启了 Android 开发者选项并启用了 USB 调试。
  2. 使用 ADB 命令可能需要一定的技术知识,因此请务必谨慎操作。

参考

https://zhuanlan.zhihu.com/p/472074014