I want to use the ConnectivityManager
which provides the getAllNetworkInfo()
method for checking the availability of network in Android. This method was deprecated in API level 23. And the developer documentation is suggesting to use getAllNetworks()
instead. I tried but couldn't get the exact functionalities which I was getting out of my old code. Please someone could guide me how to use the getAllNetworks()
method?
public boolean isConnectingToInternet(){
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
@SuppressWarnings("deprecation")
NetworkInfo[] info = connectivity.getAllNetworkInfo();
//use getAllNetworks() instead
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
return false;
}