I want to check whether the gprs connection is active or not in android through code to show how can i check that. i have the following code. Will it work?
public static boolean isOnline(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo().isConnectedOrConnecting()) {
URL url = new URL("https://telemeter4tools.services.telenet.be/TelemeterService");
HttpURLConnection urlc = (HttpURLConnection) url
.openConnection();
urlc.setRequestProperty("User-Agent", "My Android Demo");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1000); // mTimeout is in seconds
urlc.connect();
if (urlc.getResponseCode() == 200) {
return true;
} else {
return false;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
can i replace that site with the google and check the response.
yes and also replace
https
withhttp
and no need to HIT page and get response.Just make HEAD