I have tried with the following function to test Internet availability :
public boolean isNetworkAvailable(){
ConnectivityManager conn=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
Network net=conn.getActiveNetwork();
NetworkCapabilities nc=conn.getNetworkCapabilities(net);
if(net==null){
return false;
}else{
return true;
}}
return false;
}
It works great, but in the case the mobile doesn't have internet and mobile data is enabled the Application keeps crushing. So if someone tried resolving this issue please show me how. I'm working on my first Android project. I have tested some solutions from here: how to check internet connection is available, but it still not working.
thanks for replying !