I need to tell if my device has Internet connection or not. I found many answers like:
private boolean isNetworkAvailable() {
ConnectivityManager connect
The latest way to do that from the documentation is to use the ConnectivityManager to query the active network and determine if it has Internet connectivity.
public boolean hasInternetConnectivity() {
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return (activeNetwork != null &&
activeNetwork.isConnectedOrConnecting());
}
Add these two permissions to your AndroidManifest.xml file: