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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:59:48+00:00 2026-05-15T02:59:48+00:00

I tried in many ways to check Internet connection in my android emulator ConnectivityManager

  • 0

I tried in many ways to check Internet connection in my android emulator

  ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);  

   NetworkInfo info= conMgr.getActiveNetworkInfo();  

         if(info != null || info.isConnected()) {  
              Log.v("NetworkInfo","Connected State");  
         }  
        else{  
            Log.v("NetworkInfo","Not Connected state");  
            Log.v("Reason",info.getReason());  
        } 

even if i disable Internet connection in my system ,my code seems to display Connected state
so i guessed this may work

 if ( conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED
        ||  conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED  ) {

      Log.v("Congr","Connection Present");

    }
    else if ( conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED
        ||  conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED) {

      Log.v("conMgr"," No Connection");

    } 

but the above code also displays “Connection Present” even when i disconnect Internet cables.
.Please help to find a correct way to do this .I have ACCESS_NETWORK_STATE and INTERNET permission in my manifest file

  • 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-15T02:59:49+00:00Added an answer on May 15, 2026 at 2:59 am

    1 Disconnecting internet cables is irrelevant. Use F8 to switch off/on internet in the emulator

    2 In the first code this logic is wrong:

    if(info != null || info.isConnected()) {  
                  Log.v("NetworkInfo","Connected State");  
             } 
    

    It should be:

    if(info != null && info.isConnected()) {  
                  Log.v("NetworkInfo","Connected State");  
             } 
    

    If you use || then this is the result:
    a) when info is null, info.isConnected() will crash
    b) when info is not null, you will always show Connected State

    However, even if you fix that, the code wont be completely correct (see 4)

    3 In the second code, this logic is wrong:

     else if ( conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED
            ||  conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED) {
    
          Log.v("conMgr"," No Connection");
    
        } 
    

    should be:

     else {
    
          Log.v("conMgr"," No Connection");
    
        } 
    

    Why? Because there are more states than CONNECTED and DISCONNECTED.

    However, even if you fix that, the code wont be completely correct (see 4)

    4 This works on emulator and devices.

    connected = (   conMgr.getActiveNetworkInfo() != null &&
                conMgr.getActiveNetworkInfo().isAvailable() &&
                conMgr.getActiveNetworkInfo().isConnected()   )
    

    Note the use of isAvailable – without this isConnected can return TRUE when WIFI is disabled.

    Hope this helps!

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

Sidebar

Related Questions

I tried many ways to solve this problem but none works. suppose I have
I've searched and searched and tried many different ways, but I can't seem to
As SpriteMethodTest says there are many ways for drawing sprites. Firstly, I tried canvas,
I have tried many ways of executing this but its not happening .. here
I have tried many ways of Asynchronously loading images and they ALL have this
I have tried many ways to select an option with jquery including .val(0) .attr('selected',
I have tried many ways, including the following: <table style=border-collapse: collapse; width: auto; float:
I tried many ways and i still stuck. I use code: File f =
I have tried many ways to achieve this biut unable to delete row from
I know there are many people who have the problem. I've tried many ways

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.