This is my code below:
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
}
When I run the above code, I am getting a Deprecated
warning saying that getActiveNetworkInfo
and isConnected
methods are deprecated.
I don't want to continue this code for any longer. What are some of the alternatives of the above code?
Can someone please help me? Thanks in Advance
Below is my code which I use in my application to check if device is connected to network. It does not contain any deprecated code as of now.
Read more about Connectivity Manager and Network Capabilities here.