My app connect directly to a hardware device that act as an access point (with no access to internet).
I can't connect because Android 5.0 automaticcaly switch to a valid internet connection, so if I have data connection (3G, 4G, ...) or a pre-configured network I can't connect to my device because it ignores the WiFi.
So how can I force Android to use the network I activated programatically?
I'm simply using:
wifiManager.enableNetwork(id, true))
where id
is the network of my device I want to connect to. The true
parameter is useless.
The suggested solution that use ConnectivityManager.requestNetwork()
has no effect.
I found a workaround to enable the desidered network on Lollipop:
WifiConfiguration enable network in Lollipop
Now this is my code after calling
wifiManager.enableNetwork(id, true)
:maybe the secret is the call to
reconnect()
, I don't know at this time.UPDATE Unfortunately, this workaround only works if a valid WiFi connection is active before executing the code. Does not works if you're connect by 3G only.
UPDATE 19 Jan 2015
This code actually works for me on Android 5/6.0.x: