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.
You can try to use new Lollipop API ConnectivityManager.requestNetwork(), supposedly like this:
ConnectivityManager cm = (ConnectivityManager) Context.getSystemService(Context.CONNECTIVITY_SERVICE); cm.requestNetwork(new NetworkRequest.Builder() .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) .setNetworkSpecifier("XX:XX:XX:XX:XX:XX") .build(), new ConnectivityManager.NetworkCallback() { void onAvailable(Network network) { } });
where XX:XX:XX:XX:XX:XX
is your WiFi SSID. I'm not sure about it's format, and if it's used at all, I did not find any references to setNetworkSpecifier
inside Android sources, except for the NetworkCapabilities
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With