Check If The User Is Connected To The Internet And If Not Prompt The User To Turn On Data Services Android
I am making a check if the user is connected to the internet. If the user is not connected then prompt the user to turn on data services. This is the code that I am using to prompt
Solution 1:
public boolean isNetworkAvailable() {
ConnectivityManager connectivity = (ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
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;
}
Post a Comment for "Check If The User Is Connected To The Internet And If Not Prompt The User To Turn On Data Services Android"