Java: Checking Internet Connectivity


/ Published in: Java
Save to your folder(s)

Need to check if your device is online before sending/getting a request? Here's how.


Copy this code and paste it in your HTML
  1. public boolean isOnline() {
  2. ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  3. return cm.getActiveNetworkInfo().isConnectedOrConnecting();
  4.  
  5. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.