Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7045695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:33:42+00:00 2026-05-28T02:33:42+00:00

I am using following method to check if device has access to internet. In

  • 0

I am using following method to check if device has access to internet.
In this code i am trying to ping/request to www.google.com

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;
}

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.

I am doing this check in the onCreate of the activity.
Is there another why of doing this check.

UPDATE:
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.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:33:43+00:00Added an answer on May 28, 2026 at 2:33 am

    You can check if the device is connected to a network easily enough or if you really want to see if the device can connect to Google specifically without the delay wrap that code in an ASync task.

    Information on ASync task: http://developer.android.com/reference/android/os/AsyncTask.html

    An AsyncTask will allow you to run the code on a thread seperate than the UI thread. Currently it’s freezing for 1 – 2 seconds for that reason.

    EDIT I haven’t provided code for checking wireless connectivity as others have already provided other alternatives but I did think it was important to explain why you’re experencing the freeze you are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to check Internet connectivity on Android using the following method. I
I am using the following method to reverse geocode a google maps latlng: [GClientGeocoder.getLocations(address:String,
I'm using the following method in my code: - (NSMutableArray *) newOrderedArray:(NSMutableArray *)array ByKey:(NSString
In the Application Delegate didFinishLaunching method, I am using the following code to build
I am using the following code to generate and parse the XML. The method
I am using following code to check first four characters are alphabate or not.
I am using a method that has the following signature: public static bool TryAuthenticate(string
I'm using the following method to send mail from Python using SMTP. Is it
I am using the following method: set_browser_log_level 'off' but my log level continues to
I am using the following method to browse for a file: OpenFileDialog.ShowDialog() PictureNameTextEdit.Text =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.