Reputation: 6567
How do I check any kind of network status in Android?
Upvotes: 0
Views: 1625
Reputation: 43
can check network availability or not
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
Upvotes: 0
Reputation: 6653
For checking the network this function will help you.
`public boolean InternetConnection()
{
ConnectivityManager connectivity = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}`
if the network is there it will return true otherwise it will return false.
Upvotes: 1
Reputation: 760
if (Context.getSystemService(Context.CONNECTIVITY_SERVICE).getNetworkInfo(
ConnectivityManager.TYPE_MOBILE)
|| Context.getSystemService(Context.CONNECTIVITY_SERVICE).getNetworkInfo(
ConnectivityManager.TYPE_WIFI) {
// do something
}
Upvotes: 4