Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android 6.0.1 force wifi connection with no internet access

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

like image 672
Ray Tayek Avatar asked May 13 '16 20:05

Ray Tayek


People also ask

Why does my Android say connected to WiFi but no internet?

A common reason why your phone has a WiFi connection but no Internet access is that there is a technical issue with your router. If your router is experiencing any kind of bugs or problems, that affects how your devices including your Android devices connect to the Internet.

Why does my WiFi says connected but no internet access on my phone?

Reset Android Network Settings. Open the Settings app and go to “Reset options”. Now, tap on the “Reset Wi-Fi, mobile & Bluetooth“ option. On the next page, tap on the “Reset Settings” button at the bottom. After resetting, try to connect to the WiFi network and see if it fixes the issues.

Why can’t I connect to the Internet on my Android phone?

At times, when you have mobile data turned on and then connect to a WiFi network, you might not be able to access the internet. So, try disabling mobile data to fix the issue. Now, you might be thinking Android is too smart for this. But occasionally, when you connect to a WiFi network, Android will prioritize WiFi over the mobile data.

How to fix WiFi not working on Android devices?

Open the Settings app and go to “Reset options”. Now, tap on the “Reset Wi-Fi, mobile & Bluetooth “ option. On the next page, tap on the “Reset Settings” button at the bottom. After resetting, try to connect to the WiFi network and see if it fixes the issues.

Why won't My Device autoconnect to my WiFi?

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.

Does Android use mobile data when connected to WiFi?

But occasionally, when you connect to a WiFi network, Android will prioritize WiFi over the mobile data. However, some networks require users to log in before they can access the internet. Even after logging in, Android might not see it as an active connection and still use mobile data.


1 Answers

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!

like image 51
Olaia Avatar answered Sep 24 '22 17:09

Olaia