title: android 6.0.1 force wifi connection with no internet access
body: <p>this has many similar questions (google for: "no internet access detected. won't automatically reconnect." or: android force wifi connection programmatically).</p>
  
  <p>i thought i had a answer <a href="https://stackoverflow.com/questions/35282807/android-studio-1-5-1-marshmallow-no-internet-access-detected-wont-automaticall">here</a>, but it stopped working after installing 6.0.1 updates (i have may 1 security patches).</p>
  
  <p>seems like this is a <a href="https://github.com/eryngii-mori/android-developer-preview/issues/2218" rel="noreferrer">behaviour change</a>.</p>
  
  <p>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().</p>
  
  <p>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.</p>
  
  <p>but the wifi says: "no internet access detected. won't automatically reconnect" after the router cycles power.</p>
  
  <p>doing a disconnect, enable, reconnect does not work. at best it gets: ip6-localhost/::1.</p>
  
  <p>has anyone had any luck using a request object, or bindProcessToNetwork?</p>
  
  <p>edit: <a href="https://android.stackexchange.com/questions/100657/how-to-disable-captive-portal-detection-how-to-remove-exclamation-mark-on-wi-fi">related</a>.</p>
  
  <p>edit: the problem seems to be with: CAPTIVE_PORTAL_DETECTION_ENABLED - this string <em>seems</em> to be defined in the source:</p>
  
  <pre><code>public static final String
          CAPTIVE_PORTAL_DETECTION_ENABLED = "captive_portal_detection_enabled";
      ...
      MOVED_TO_GLOBAL.add(Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED);
  </code></pre>
  
  <p>but throws" android.provider.Settings$SettingNotFoundException: captive_portal_detection_enabled when used explicitly and is not visible to android studio.</p>
  
  <p>also, doing a settings list global does not contain the constant.</p>
  
  <p>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 <em>seems</em> 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.</p>
  
  <p>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.</p>
  
  <p>edit: trying to exec the shell command throws: java.lang.SecurityException, so it looks like you need to issue the command from adb :(</p>
  
  <p>thanks </p>