Saturday 8 June 2019

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...