i need to check internet connection with in fraction of seconds. currently i am using this code for checking internet connection but it is taking time to check internet connection. here i am using http request and response, i send one request with some website like google, after that only i got response. is it possible to get the connection while sending request. i need to check within seconds please help me
try {
if (currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
HttpURLConnection urlc = (HttpURLConnection) (new URL("http://www.google.com").openConnection());
urlc.setRequestProperty("User-Agent", "Test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1500);
urlc.connect();
if(urlc.getResponseCode() == 200)} catch (IOException e) {
Log.e(TAG, "Error checking internet connection", e);
}
thankyou