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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:18:34+00:00 2026-05-15T03:18:34+00:00

I am attempting to get the string representation of an Android device’s current WiFi

  • 0

I am attempting to get the string representation of an Android device’s current WiFi state. I am using the getWifiState() method of the WiFiManager and am getting an integer returned depending on the current state. This makes total sense as getWifiState() is supposed to return an integer. The method’s documentation indicates that the possible return values translate to one of the following constant values

  • 0 WIFI_STATE_DISABLING
  • 1 WIFI_STATE_DISABLED
  • 2 WIFI_STATE_ENABLING
  • 3 WIFI_STATE_ENABLED
  • 4 WIFI_STATE_UNKNOWN

Is there an easy way to translate the integer returned from getWiFiState() to a string representation? I’ve looked at getIntExtra but am unsure of its use.

  • 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-15T03:18:35+00:00Added an answer on May 15, 2026 at 3:18 am

    i know you already accepted an answer but you should not use the code posted because, as you said, it is brittle and difficult to maintain. There is no reason for it to be so.

      public String getWifiStateStr() {
        switch (mWifiManager.getWifiState()) {
          case WifiManager.WIFI_STATE_DISABLING:
            return "disabling";
          case WifiManager.WIFI_STATE_DISABLED:
            return "disabled";
          case WifiManager.WIFI_STATE_ENABLING:
            return "enabling";
          case WifiManager.WIFI_STATE_ENABLED:
            return "enabled";
          case WifiManager.WIFI_STATE_UNKNOWN:
            return "unknown";
          default:
            return null;  //or whatever you want for an error string
        }
      }
    

    This protects you from changes in the constant assignment, will be much easier to read in 6 months, and assuming you handle the error string correctly should limit bugs if the number of allowed return values increases.

    When you see a variable listed as a ‘Constant’ in Android documentation it means that it is declared public static final. It can be accessed as ClassName.CONST_VARIABLE_NAME. It is convention that these variables will be in all caps but it is not a language requirement. Generally speaking you should never need to use the actual value of such members, you should always access them by member name unless you need to do something odd.

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

Sidebar

Related Questions

I'm attempting to do a simple bubble sort code to get familiar with list/string
I'm attempting to use Assembly.GetType(MyCompany.Class1.Class2) to dynamically get a type from a string. Assembly.GetType(MyCompany.Class1);
I'm attempting to get my first ASP.NET web page working on windows using Mono
I'm attempting to get the following code from nmdepend to compile const std::string Bfd::packageName(const
Given a floating point number, I'm looking to get a String representation of a
While attempting to get an old svn dump of a project under git control,
I am attempting to get a DropDownList to AutoPostBack via an UpdatePanel when the
I am attempting to get the information from one table (games) and count the
I have been attempting to get log4net logging in my asp.net web application with
I am attempting to get Memory leak detection working with the help of these

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.