Here is a simple java class used to Check Internet status in your android application . This class help you check your internet status.
package com.trinity.Utils; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; /** * Created by Trinity Tuts */ public class CheckInternet { public boolean isConnected; public boolean isNetworkAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (!isConnected) { return false; } return true; } }
Use:
CheckInternet internet; internet = new CheckInternet(); // Check if (internet.isNetworkAvailable(context) == false) { Toast.makeText(context, "No internet connection!", Toast.LENGTH_LONG).show(); }
🙂