I'm using the following code to connect to a WiFi network without internet connection, because it hosts its own web-server where I want to connect even if there is no internet connection available.
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = String.format("\"%s\"", scanResult.SSID);
wifiConfiguration.preSharedKey = String.format("\"%s\"", "secret");
int netId = wifiManager.addNetwork(wifiConfiguration)
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
This works fine on every device below Android Marshmallow (I'm using CM13, so is it maybe related to CyanogenMod?): When I use this code to connect, Android still uses the mobile connection and mark the WiFi symbol with an exclamation mark. Seconds later it shows a notification with the question if I want to stay connected, because the network has no internet connection.
Problem: My app tries to connect automatically to my web-server which fail, because there is obviously no internet connection. Of course it would be possible to wait until I can reach my web-server, but it should work without user interaction.
How does ChromeCast or any other IoT device solve this? I never saw a notification like this when I was setting up my ChromeCast device.
ChromeCast -> Local Router -> PC with PDANet -> USB connect to Mobile Phone with FoxFi app installed
. – Reis