I am trying check internet state normally. When I enable internet and then I run this app it will show "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 conenction.
private boolean checkInternetConenction(){
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 conencted to internet",
Toast.LENGTH_SHORT).show();
return false;
}
}
0 comments:
Post a Comment