I am trying to check internet state normally. When I enable internet and then I run this app it shows "Internet is connected". When I stop internet and then again run this app it again it will show "not connected to internet". But when I run this app in an emulator it always shows Internet connected. Please tell me what's the problem.
//check Internet connection.
private boolean checkInternetConnection() {
ConnectivityManager check = (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (check != null) {
NetworkInfo[] info = check.getAllNetworkInfo();
if (info != null)
for (int i = 0; i <info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
Toast.makeText(context, "Internet is connected", Toast.LENGTH_SHORT).show();
}
return true;
} else {
Toast.makeText(context, "not connected to internet", Toast.LENGTH_SHORT).show();
return false;
}
}