Question
getActiveNetworkInfo() is deprecated in API 29
I am using a code that check if user has internet active or not but after targeting sdk29 the functions bellow became deprecated
NetworkInfo
NetworkInfo.isConnected()
getActiveNetworkInfo()
Here is the code :
public static boolean isNetworkAvailable(Context context) {
if(context == null) { return false; }
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// if no network is available networkInfo will be null, otherwise check if we are connected
try {
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
Log.i("update_statut","Network is available : true");
return true;
}
} catch (Exception e) {
Log.i("update_statut",""+ e.getMessage());
}
Log.i("update_statut","Network is available : FALSE ");
return false;
}
46 40724
46