This method is to check data connection by ping certain IP or Domain name.
Use network intents to perform tasks while data is allowed
When your device connects to a network, an intent is sent. Many apps don’t check for these intents, but to make your application work properly, you can listen to network change intents that will tell you when communication is possible. To check for network connectivity you can, for example, use the following clause:
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0