android 6.0.1强制wifi连接而无法访问互联网 [英] android 6.0.1 force wifi connection with no internet access

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

问题描述

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

我以为我有一个答案此处,但是在安装6.0.1更新(我有5月1日的安全补丁)后,它停止工作.

似乎是行为更改. >

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

已建立手动连接.有时会出现一个对话框,询问您是否始终保持连接状态.我总是会检查.

但是wifi却说:路由器重启后,没有检测到互联网访问.不会自动重新连接."

进行断开连接,启用,重新连接不起作用.最多可以得到:ip6-localhost/:: 1.

有人有没有使用请求对象或bindProcessToNetwork的运气?

但是会抛出"android.provider.Settings $ SettingNotFoundException:当明确使用且在android studio中不可见时,captive_portal_detection_enabled.

此外,全局设置列表也不包含常量.

edit在进行adb shell设置时,将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(假).

实际上发生的是,默认情况下,每次您连接到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 settings list global | grep "captive"

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

希望有帮助!

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连接而无法访问互联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆