I am a beginner in Android and I am working to develop an application that requires internet connection. but I can't find any API function to detecting changes on internet connection as shown in the following pictures
Device connected to a network and Internet is not available
Device connected to a network and Internet is available
I have tried the following code but it is not what I want
public static boolean checkInternetConenction(Context context) {
ConnectivityManager
cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null
&& activeNetwork.isConnectedOrConnecting();
}
The previous code only returns if the device is connected to a network or not.