android 6.0.1 强制 wifi 连接,无法访问互联网

android 6.0.1 force wifi connection with no internet access(android 6.0.1 强制 wifi 连接,无法访问互联网)

本文介绍了android 6.0.1 强制 wifi 连接,无法访问互联网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有很多类似的问题(谷歌:未检测到互联网访问.不会自动重新连接."或:android 以编程方式强制 wifi 连接).

我以为我有答案 这里,但在安装 6.0.1 更新后它停止工作(我有可能 1 个安全补丁).

这似乎是一个行为改变.p>

我有一些带有 6.0.1 的 2013 年 nexus 7,它们运行信息亭类型的应用程序,并希望以编程方式连接到没有互联网连接的特定无线网络.每个平板电脑都有一个唯一的静态 IP 地址,格式为:192.168.0.xx.我使用普通的 java 套接字构造函数并检查接口是否已使用:NetworkInterface.getNetworkInterfaces().

已建立手动连接.有时会有一个对话框询问您是否要始终连接.我总是检查是.

但 wifi 显示:未检测到互联网访问.在路由器重启后不会自动重新连接".

断开、启用、重新连接不起作用.充其量它得到:ip6-localhost/::1.

有没有人在使用请求对象或 bindProcessToNetwork 时遇到过运气?

相关的.

问题似乎出在:CAPTIVE_PORTAL_DETECTION_ENABLED - 此字符串似乎在源代码中定义:

public static final StringCAPTIVE_PORTAL_DETECTION_ENABLED = "captive_portal_detection_enabled";...MOVED_TO_GLOBAL.add(Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED);

但会抛出android.provider.Settings$SettingNotFoundException: captive_portal_detection_enabled 显式使用且对 android studio 不可见.

另外,做一个全局设置列表不包含常量.

编辑做 adb shell settings put global captive_portal_detection_enabled 0 似乎确实有效,但是当路由器循环电源时,这不能在现场完成.此值似乎在平板电脑循环电源时仍然存在.现在这个值显示在全局设置列表中.另外,使用原始字符串: Settings.Global.getInt(getContentResolver(),"captive_portal_detection_enabled");现在返回 0.

看起来设置它需要:android.permission.WRITE_SECURE_SETTINGS,但是当放入清单时当然会失败,因为我们不是系统应用程序.

尝试执行 shell 命令抛出:java.lang.SecurityException,所以看起来你需要从 adb 发出命令:(

谢谢

解决方案

您可以尝试将全局设置 captive_portal_detection_enabled 设置为 0 (false).

实际发生的情况是,默认情况下,每次您连接到 wifi 时,FW 都会针对服务器(通常是 google)进行测试,以查看它是否是强制 wifi(需要登录).因此,如果您的 wifi 未连接到 google,则此检查将失败.之后,设备知道 wifi 没有互联网连接,根本不会自动连接到它.

将此设置设置为 0,将避免此检查.

以编程方式Settings.Global.putInt(getContentResolver(), Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED, 0);

您可以通过 adb 来进行测试:

adb shell settings put global captive_portal_detection_enabled 0

并像这样检索它的值:

adb shell 设置列表全局 |grep 俘虏"

恕我直言,这不是一件好事,因为您正在为用户更改设置,而许多 FW 甚至没有提供高级设置来由用户自己启用/禁用此设置.(谷歌没有).但也许它适合您的需求.

希望对你有帮助!

this has many similar questions (google for: "no internet access detected. won't automatically reconnect." or: android force wifi connection programmatically).

i thought i had a answer here, but it stopped working after installing 6.0.1 updates (i have may 1 security patches).

seems like this is a behaviour change.

i have some 2013 nexus 7's with 6.0.1 that run a kiosk type app and want to connect programmatically to a specific wireless network that has no internet connection. each tablet has a unique static ip address of the form: 192.168.0.xx. i use the normal java socket constructors and check to see if the interface is up using: NetworkInterface.getNetworkInterfaces().

a manual connection has been made. sometimes there is a dialog that asks whether or not you want to always connect. i always check yes.

but the wifi says: "no internet access detected. won't automatically reconnect" after the router cycles power.

doing a disconnect, enable, reconnect does not work. at best it gets: ip6-localhost/::1.

has anyone had any luck using a request object, or bindProcessToNetwork?

edit: related.

edit: the problem seems to be with: CAPTIVE_PORTAL_DETECTION_ENABLED - this string seems to be defined in the source:

public static final String
        CAPTIVE_PORTAL_DETECTION_ENABLED = "captive_portal_detection_enabled";
    ...
    MOVED_TO_GLOBAL.add(Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED);

but throws" android.provider.Settings$SettingNotFoundException: captive_portal_detection_enabled when used explicitly and is not visible to android studio.

also, doing a settings list global does not contain the constant.

edit doing a adb shell settings put global captive_portal_detection_enabled 0 does seem to work, but this can not be done in the field when the router cycles power. this value seems to persist when the tablet cycles power. and now this value shows up in a settings list global. also, using the raw string: Settings.Global.getInt(getContentResolver(),"captive_portal_detection_enabled"); now returns 0.

edit: looks like setting it requires: android.permission.WRITE_SECURE_SETTINGS, but of course this fails when put into the manifest since we are not a system app.

edit: trying to exec the shell command throws: java.lang.SecurityException, so it looks like you need to issue the command from adb :(

thanks

解决方案

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);

You can do it through adb for testing purposes:

adb shell settings put global captive_portal_detection_enabled 0

And retrieve it's value like this:

adb shell settings list global | grep "captive"

IMHO this is not very nice thing to do, since you are changing a setting for the user and many FWs don't provide even an advanced setting to enable/disable this by the user itself. (Google doesn't). But maybe it suits your needs.

Hope it helps!

这篇关于android 6.0.1 强制 wifi 连接,无法访问互联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:android 6.0.1 强制 wifi 连接,无法访问互联网

基础教程推荐