I am building an android app that notifies a user when the internet connection is active again. He/she has to enable the feature when the internet is not working. What is the best way to do this? Currently I am running an infinite loop ping request to google in a service but it doesn't continue after few thousand requests. Are there any simpler or better ways to achieve this? Thank you.
Edit: Most of the answers and references check only if my device is connected to Wifi. But what if my device is connected to my router but the internet connection is not working?
I'm using broadcast to check the connection every time. Create a class for connection info.
Apply code into your Activity:
Register broadcast in your activity's
onCreate()
method:Don't forget to unregistered/register on Activity cycle: