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