To perform the check I use the following utility method:
private boolean isNetworkAvailable()
{
ConnectivityManager connectivityManager
= (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo =
connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
Remember you need the following in your AndroidManifest.xml in order for your app to connect to the Internet:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
No comments:
Post a Comment
Note: only a member of this blog may post a comment.