Skip to content

Instantly share code, notes, and snippets.

@manarFci
Created July 20, 2019 15:14
Show Gist options
  • Save manarFci/2b77804615d8173d35656c8c8126be7e to your computer and use it in GitHub Desktop.
Save manarFci/2b77804615d8173d35656c8c8126be7e to your computer and use it in GitHub Desktop.
check Network connectivity
package com.example.android.quakereport;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* Created by macbook on 7/20/19.
*/
public class NetworkHelper {
public static boolean hasNetworkAccess(Context context){
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
return isConnected;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment