2

I am working on a app that connects to another device via WiFi. I then use HttpUrlConnection to send request for JSON result.

As this WiFi connection does not have internet access, the http request is often sent via the mobile network and thus timeout. If i disable my mobile network, it changes my WiFi to another one that has internet access.

So I would like to find out if i can achieve the followings:-

1) Restrict my app to go through the WiFi network instead of the mobile network even though it has no internet access

2) Can i prevent the WiFi change

Scenario:

1) My app is on Device A (has internet), it then connects to Device B (no internet) via WiFi.

2) When I send the http request from A to B, it went to the mobile network instead to Device B.

3) If i disable mobile data on Device A, it auto change the WiFi to another network with internet, thus disconnect from B.

4) My question is how to send request ONLY to B.

Thanks.

Alan Chan
  • 21
  • 3
  • can you please elaborate your question? If you really want your app to work in WIFI only, you are having network change listeners. – Sai's Stack May 12 '17 at 09:54
  • scenario added, hopefully it's clearer now. thanks. – Alan Chan May 12 '17 at 10:06
  • welcome. add a flag to my answer. – Sai's Stack May 12 '17 at 10:06
  • 1
    Possible duplicate of [Restrict network access to only via WiFi](http://stackoverflow.com/questions/13806813/restrict-network-access-to-only-via-wifi) – IAmGroot May 12 '17 at 10:11
  • @Doomsknight, correct me if i'm wrong, but the link is for WiFi with internet. It could solve the first part of my question, how about the second part? thanks. – Alan Chan May 12 '17 at 10:44
  • No worries, only flagging incase it helps you. If you restrict it to just wifi network, then only set your device to only remember the network B, would that not solve the issue? Aka, it would only swap to networks it remembers. If you click forget network, it wont auto connect to anything you dont want. This would keep if on wifi only, on device B only. – IAmGroot May 12 '17 at 11:15
  • will give the WiFiP2P suggested by Anamika Rathore a try first. if it fails then use your suggestion. will post my result soon. thanks. – Alan Chan May 13 '17 at 13:22

0 Answers0