×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Massimo Zappino
Added: Oct 31, 2012 8:19 AM
Modified: Oct 31, 2012 8:54 AM
Views: 47
Via http://www.vogella.com/articles/AndroidNetworking/article.html#networkstate
  1. public boolean isNetworkAvailable() {
  2.     ConnectivityManager cm = (ConnectivityManager)
  3.       getSystemService(Context.CONNECTIVITY_SERVICE);
  4.     NetworkInfo networkInfo = cm.getActiveNetworkInfo();
  5.     // if no network is available networkInfo will be null
  6.     // otherwise check if we are connected
  7.     if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
  8.         return true;
  9.     }
  10.     return false;
  11. }

1 comment

Massimo Zappino 4 years ago
You need to add the android.permission.ACCESS_NETWORK_STATE permission in your AndroidManifest.xml

Write a comment