Monday, September 24, 2018

how to stop asynctask when internet is connected but no internet access in android

String url = "http://xyzcloud.com/xyz/xyz.php";



this the url am trying to get the data from cloud,if internet is connected then async task will execute
i wrote this method for checking wether internet is connected or not, here in my mobile wifi is connetecd when am trying to execute it is giving exception



public boolean checkOnlineState()
{
boolean val = false;
ConnectivityManager CManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo NInfo = CManager.getActiveNetworkInfo();

if (NInfo != null && NInfo.isConnectedOrConnecting()) {
try {
if (InetAddress.getByName(url).isReachable(10000))
{
// host reachable
val=true;
Log.e("checkOnlineState", "" + val);
}
else
{

// host not reachable
val = false;
Log.e("checkOnlineState", "" + val);
}
} catch (IOException e) {
e.printStackTrace();
}
}

return val;

}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...