Reputation: 29573
Does anybody know of a way to have my application constantly check firstly if there is internet connectivity..and secondly if there is internet connection to call a function...It needs to check for internet coverage say every 10 minutes etc?
Upvotes: 0
Views: 159
Reputation: 2213
Use ConnectivityManager to check for network connectivity.
ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo.isConnected())
{
// do something
}
To wake the device every 10 minutes, use the API provided by AlarmManager. I don't have practical experience using the AlarmManager; please refer to this tutorial, which seems fairly comprehensive
Do keep in mind that waking the device this often will have a noticeable effect on battery life.
Upvotes: 1