Closed broakenmedia closed 8 years ago
Let's define the enhancements:
Do you have any other suggestions?
Well, i wouldn't say you yourself would need to implement those. I would probably say, let the library continue to be a check for "adapters being enabled" then place the pinging duties on the developer but provide a manual means with which to tell connection buddy that the connection is offline.
Actually, I really like the idea to ping some remote server in order to determine if network request can be executed over mobile data. I'm going to add this to version 1.1.0, it could be really helpful.
You can use ConnectionBuddy.getInstance().hasNetworkConnection() to determine the connection state - it will check both WiFi and mobile network state and return false if connection is currently offline.
Great stuff :+1: :) hasNetworkConnection however will still really only check if that adapters are ON/Available. Without a ping of some sort it's impossible to tell! Not to worry though. I've just set this up myself manually for now.
Lastly, just a quick thing to help you implement. You'll probably want to use this url for pinging against:
http://clients1.google.com/generate_204
It's actually the URL google themselves use in Chrome etc.. to determine if the user is on a hotel wifi hotspot for example (i.e. Connected to wifi and a network but not actually got access to the internet)
Thanks Joe, this is really excellent idea! I'll start working on it soon, this is probably going to be the last feature which will go into version 1.1.0.
Glad to hear it! I look forward to using it :)
Do let me know if you need me for anything!
@xbroak Could you please take a look at #59 and provide me with some feedback? I think that this should cover all of the defined use-cases.
@zplesac That was quick! I'm actually struggling to see anything to comment on. It's almost identical to what i'd implemented. Good job!
Great, I'll merge the changes than into development and release new version soon.
Merged.
OK, so this library can truly only detect whether A: Wifi is ON/OFF and B: 3G is ON/OFF it does not actually know if for instance, 3G is enabled, but the user is out of credit on their phone, thus the internet is not TRULY available. At this point, I'm firing off a "ping check" with a google server to determine the true online state. Depending on the result of that call it would be great to be able to "override" ConnectionB to say, "The internet is ON/OFF" and propagate the usual callbacks