Reputation: 7011
You can check if there's connectivity on Android by using this snippet as stated here
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork.isConnectedOrConnecting();
But what data does ConnectivityManager
need to state that the device is currently connected and functional?
As seen on the AOSP source code for ConnectivityManager.java file NetworkInfo it´s just a container of the information that ConnectivityManager
builds. But ConnectivityManager
gets all the data from a Interface called IConnectivityManager. I´ve lost the trace here.
public NetworkInfo getActiveNetworkInfo() {
try {
return mService.getActiveNetworkInfo();
} catch (RemoteException e) {
return null;
}
}
Can someone throw a little light here?
Upvotes: 0
Views: 413
Reputation: 32780
ConnectivityManager
calls getActiveNetworkInfo
of ConnectivityService:
@Override
public NetworkInfo getActiveNetworkInfo() {
enforceAccessPermission();
final int uid = Binder.getCallingUid();
NetworkState state = getUnfilteredActiveNetworkState(uid);
return getFilteredNetworkInfo(state.networkInfo, state.linkProperties, uid);
}
getUnfilteredActiveNetworkState
[1]getDefaultNetwork
[2]NetworkAgentInfo
from the SparseArray
mNetworkForRequestId
[3]Upvotes: 1