NetworkUtils.java
public class NetworkUtils { public static boolean isInternetConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } return false; } }
Java
if (NetworkUtils.isInternetConnected(this)) { // Internet is connected, proceed with your intent or desired logic // ... } else { // No internet connection, show a dialog or handle the case accordingly // ... }
Tags:
Android Studio