How to check if android device has access to internet?
<p>I am using following method to check if device has access to internet.<br>
In this code i am trying to ping/request to <code>www.google.com</code>  </p>

<pre><code>try
{
    HttpGet request = new HttpGet(new URI(WEB_SIT_TO_PING));
    HttpParams httpParameters = new BasicHttpParams();  

    HttpConnectionParams.setConnectionTimeout(httpParameters, 500);
    HttpConnectionParams.setSoTimeout(httpParameters, 500);

    HttpClient httpClient = new DefaultHttpClient(httpParameters);
    HttpResponse response = httpClient.execute(request);

    int status = response.getStatusLine().getStatusCode();
    if (status == HttpStatus.SC_OK) 
    {
        result = true;
    }
}
catch(Exception e)
{
    e.printStackTrace();
    result = false;
}
</code></pre>

<p>Above code works but, when my activity gets launched it displays one blank black screen for 1-2 seconds and then it displays the main screen of the activity.   </p>

<p>I am doing this check in the <code>onCreate</code> of the activity.<br>
Is there another why of doing this check.  </p>

<p>UPDATE:<br>
I don't want to check if Network is connected or not, I want to check if Device has Access to Internet. It may be the case that Device has Network connection but that network connection does not have Internet Access.  </p>

<p>Thanks.</p>
