0

Are there any APIs to check if the WiFi which the Android device is connected to, really serves internet or not?
whenever the device is connected to WiFi, it considers it as online though the Wifi router does not serve internet or idle.

How to check in such situations?
I tried doing some research about this. But came across the method of pinging some site or google DNS to check for connectivity everywhere.
But i want to know if there are any APIs which detects the situation.

Roohi Zuwairiyah
  • 363
  • 3
  • 15
  • https://stackoverflow.com/a/9570292/4794878 – Suhayl SH Jun 12 '18 at 05:09
  • @SuhaylSH i went through the answers in the link you have told. Most of them are checking the method of pinging any site. One has told that there are no inbuilt method to check this situation. But that comment is old. I want to know whether there are any **APIs** or **inbuilt-methods** methods available as of today. – Roohi Zuwairiyah Jun 12 '18 at 05:22
  • I don't think there is any API for it. Pinging the backed server url should be reliable! – Suhayl SH Jun 12 '18 at 06:38

1 Answers1

2

You can use connectivity manager's getActivityNetworkInfo() to check whether the device is connected to any network or not.

But in your case where the device is connected to wifi but wifi is not connected to the internet, there is no API of such kind to check this, you need to do by accessing/pinging any website only. Best would be to access your backend server URL or any web service URL if you are using.

Rajen Raiyarela
  • 5,526
  • 4
  • 21
  • 41