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 8410709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:14:57+00:00 2026-06-10T00:14:57+00:00

Possible Duplicate: Android – detect whether there is an Internet connection available this is

  • 0

Possible Duplicate:
Android – detect whether there is an Internet connection available

this is the code to check the internet availability on android device:

public boolean isInternetAvailable() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo() != null)
        return cm.getActiveNetworkInfo().isConnected();
    else
        return false;
}

So this code is working correctly if no wifi or network available.

But if device is connected to wifi network but internet is not available then what should i do to check the internet is there or not?

any suggestion will be appreciated.

  • 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-06-10T00:14:59+00:00Added an answer on June 10, 2026 at 12:14 am

    I do it like this:

    I try to reach google.com and watch for response:

    public static void isGoogleAvailable(final Handler handler)
    {
        new Thread()
        {
            private boolean hasGoogleResponded = false;
            @Override
            public void run()
            {
                new Thread()
                {
                    @Override
                    public void run()
                    {
                        HttpGet requestForTest = new HttpGet("https://www.google.com/");
                        try
                        {
                            new DefaultHttpClient().execute(requestForTest);
                            hasGoogleResponded = true;
                        }
                        catch (Exception e)
                        {}
                    }
                }.start();
    
                try
                {
                    int waited = 0;
                    while(!hasGoogleResponded && (waited < 60000))
                    {
                        sleep(100);
                        if(!hasGoogleResponded )
                        {
                            waited += 100;
                        }
                    }
                }
                catch(InterruptedException e)
                {}
                finally
                {
                    if (hasGoogleResponded)
                    {
                        handler.sendEmptyMessage(1);
                    }
                    else
                    {
                        handler.sendEmptyMessage(0);
                    }
                }
            }
        }.start();
    }
    

    Then I retrive messages in my handler:

    Handler internetHandler = new Handler()
    {
        @Override
        public void handleMessage(Message msg)
        {
            if (msg.what == 1) //connected
            {
    
            }
            else //not connected
            {
    
            }
        }
    };
    

    I hope this helps.

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

Sidebar

Related Questions

Possible Duplicate: Android - detect whether there is an Internet connection available How to
Possible Duplicate: Android ImageButton with a selected state? I was wondering whether there is
Possible Duplicate: Android findViewbyId with a variant string I have this type of code
Possible Duplicate: Android and XMPP: Currently available solutions I've started prototyping a multiplayer Android
Possible Duplicate: Android Button Tooltip Is there any way to construct a view where
Possible Duplicate: Android Webview - Webpage should fit the device screen I want to
Possible Duplicate: Android NoSuchAlgorithmException: SSLContext SSL implementation not found Has anybody experience with this
Possible Duplicate: Android - Barcode Scanning, Options? Zxing? Android: Is there a way to
Possible Duplicate: Will Google Android ever support .NET? Is there a way to develop
Possible Duplicate: how to change position of Toast in android? Is there any method

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.