Monday, 19 August 2013

keep checking for the network connectivity android

keep checking for the network connectivity android

hi I am using this code in the login screen of my android app for checking
the network connectivity is available or not. and is working fine.
public static boolean checkNetworkConnection(Context context) {
final ConnectivityManager connMgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi = connMgr
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile = connMgr
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifi.isConnectedOrConnecting() ||mobile.isConnectedOrConnecting())
return true;
else
return false;
}
But I thought of a case --
My app is fetching some data from the server and showing in table.Now I
opened the app and while fetching the data connection goes of.Now I dont
want to refresh the app or page to fetch data from the server. I want a
background process should run or thread which will keep checking for
connectivity and as soon as it get the connection it should fetch data
automatically.
Can any body help me with this.

No comments:

Post a Comment