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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:42:09+00:00 2026-06-11T12:42:09+00:00

This code always returns true. This gets called when a Login button is pressed.

  • 0

This code always returns true. This gets called when a Login button is pressed. I first tried with wifi connected (on emulator). It returned true and then I disconnected wifi and then tried. it still returns true.

public static boolean isNetworkAvailable( Context context) {

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = cm.getActiveNetworkInfo();
            // if no network is available networkInfo will be null
            // otherwise check if we are connected
            if (networkInfo != null && networkInfo.isConnected()) {
                 State network = networkInfo.getState();
                 Log.d("here", "true");
                 return (network == NetworkInfo.State.CONNECTED || network == NetworkInfo.State.CONNECTING);

            }
            Log.d("here1", "false");
            return false;
}
  • 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-11T12:42:11+00:00Added an answer on June 11, 2026 at 12:42 pm

    This code works on-device, as I’m using something very similar in one of my apps. Keep in mind that this code will tell you whether you are connected to a network, not whether the network you are connected to has internet connectivity. If you’re using the emulator, it’s always connected via 3G simulation, so disconnecting your computer’s wifi won’t change that. You could put the emulator in airplane mode, which should give you the “false” you were looking for.

    What I’ve done in my apps is to create a service which receives network change broadcasts. Once a network is connected, it then tries to download a known (small) file over the internet. Only if that succeeds will it then broadcast an internet-available intent to all the activities, which can then change state based on this.

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

Sidebar

Related Questions

I have this code and it always returns -1.I have three tables (a picture
as all you know $(#ID) returns the element having ID. but this code always
Visual Studio C++ 2008 I am using this code. However, gethostbyname always returns an
Location returns always null from this code. Please check my codes and tell me
I am new to programming. I don't understand what's wrong. This code always returns
this code always return '0' i don't know why Dim cur_month = DatePart(DateInterval.Month, Now).ToString()
Why does this code always return 0? var possibleMatches = new Array(); $.getJSON('getInformation.php', function(data)
With this code I guess the scan was faster, but the scan always return
Does this code always evaluate to false? Both variables are two's complement signed ints.
I want obtain full URL adres in php script, tell please, this code always

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.