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

  • Home
  • SEARCH
  • 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 8430279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:33:50+00:00 2026-06-10T05:33:50+00:00

I’m just trying to write a simple Android app that programatically shows whether the

  • 0

I’m just trying to write a simple Android app that programatically shows whether the WiFi is enabled or disabled. I’m unable to get it to print the Wifi status. I’m pretty sure that my code is 99% correct, but that’s no better than being 0% correct.

My code is below.

package com.jasonhsu.wifitest;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

    private LinearLayout ShowWifiStatus;
    TextView TextWifiStatus;

    @Override
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ShowWifiStatus = new LinearLayout (this);
        TextView TextWifiStatus = new TextView (this);
        TextWifiStatus.setText("Sorry, your Wifi status program isn't working.");
        this.registerReceiver(this.WifiStateChangedReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
        ShowWifiStatus.addView(TextWifiStatus);
        setContentView(ShowWifiStatus);
    }

    private BroadcastReceiver WifiStateChangedReceiver
    = new BroadcastReceiver(){

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub

            int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE , 
                    WifiManager.WIFI_STATE_UNKNOWN);

            switch(extraWifiState){
            case WifiManager.WIFI_STATE_DISABLED:
                TextWifiStatus.setText("WIFI STATE DISABLED");
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                TextWifiStatus.setText("WIFI STATE DISABLING");
                break;
            case WifiManager.WIFI_STATE_ENABLED:
                TextWifiStatus.setText("WIFI STATE ENABLED");
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                TextWifiStatus.setText("WIFI STATE ENABLING");
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                TextWifiStatus.setText("WIFI STATE UNKNOWN");
                break;
            }

        }};

}
  • 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-10T05:33:52+00:00Added an answer on June 10, 2026 at 5:33 am

    Remove the first “TextView” from the following statement so that you assign the new TextView object to the member variable TextWifiStatus instead of a local variable with the same name.

    TextView TextWifiStatus = new TextView (this);
    

    Regards

    Ziteng Chen

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.