8

I am working on a App and I need to talk to my router. I need to download a file from the router with his local ip. If the router has no internet access, Android tries to download the file via mobile network.

Is there a way to force Android to use WiFi even when there is no internet access? (its a new feature of Android Marshmallow to show WiFi but using mobile network). The file is not accessible from WAN only from LAN.

I can force it, when I disable mobile network or turn on airplane mode with WiFi enabled, but this isn't an option. I need to force it programmatically for this specific download.

Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49
Informatic0re
  • 6,300
  • 5
  • 41
  • 56
  • I don't have time to distill a complete example here, but you can bind Sockets to a given Network, or even bind a whole process, using [bindProcessToNetwork] (http://developer.android.com/reference/android/net/ConnectivityManager.html#bindProcessToNetwork(android.net.Network)). – 323go Feb 12 '16 at 13:35
  • the bindProcessToNetwork requires api level 23. I will try to use connectivityManager.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, "enableHIPRI"); but with WiFi, maybe this will help. – Informatic0re Feb 12 '16 at 14:42
  • Of course it requires API level 23... and the title of your question says "Marshmallow," no? Do you need to correct your question? – 323go Feb 12 '16 at 14:54
  • yea I am not sure because it just happened with marshmallow, I could check if it is 6.0 and then use this methode. – Informatic0re Feb 12 '16 at 14:56
  • okay documentation of startUsingNetworkFeature says: In M, and above, this method is unsupported and will throw UnsupportedOperationException if called. – Informatic0re Feb 12 '16 at 15:09
  • 1
    Have You got a solution to this? I have the same issue but only on 6.0. 6.0.1 is working fine. – Lonergan6275 Sep 27 '16 at 10:40
  • @Lonergan6275 Please try this non-rooted solution [http://stackoverflow.com/a/40733515/4206925](http://stackoverflow.com/a/40733515/4206925) – MewX Nov 23 '16 at 04:05
  • @MewX how do you see this as a suitable solution? How can you 1) inform users to take these steps and 2) expect every affected user to do it. I solved the problem by using `bindProcessToNetwork(Network network)` – Lonergan6275 Nov 23 '16 at 11:56

0 Answers0