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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:48:23+00:00 2026-05-25T13:48:23+00:00

I am having some trouble with BroadCast receiver for checking the Wi-fi state. Could

  • 0

I am having some trouble with BroadCast receiver for checking the Wi-fi state. Could you please help?

This is my manifest file.

<uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-permission>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"> </uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"> </uses-permission>
<uses-permission android:name="android.permission.INTERNET"> </uses-permission>
<application 
        android:icon="@drawable/icon" 
        android:label="@string/app_name">
    <activity 
        android:name=".MainActivity"
            android:label="@string/app_name">
    <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
           <receiver android:name=".MainActivity">
<intent-filter android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
       </receiver>  
   </application>
</manifest>

And this is the MainActivity.java

public class MainActivity extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, -1);
        String msg = null;
        switch (state) {
        case WifiManager.WIFI_STATE_DISABLED:
            msg = "it is disabled";
            break;
        case WifiManager.WIFI_STATE_ENABLED:
            msg = "it is enabled";
            break;
        case WifiManager.WIFI_STATE_DISABLING:
            msg = "it is switching off";
            break;
        case WifiManager.WIFI_STATE_ENABLING:
            msg = "wifi is getting enabled";
            break;
        default:
            msg = "not working properly";
            break;
        }
        if (msg != null) {
            Log.d("************%%%%%%%%wifi state ", "WIFI" + msg);
            Toast.makeText(context, "Wifi state is" + msg, Toast.LENGTH_LONG)
                    .show();
        }
    }
}

I am unsure where am I making my mistake. Any input would be appreciated.
I am not getting any errors just that the log file doesn’t show the required message.

  • 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-25T13:48:24+00:00Added an answer on May 25, 2026 at 1:48 pm

    You have had not added the parameters for the intent filter, the final manifest should look like this

    <uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-permission>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"> </uses-permission>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"> </uses-permission>
    <uses-permission android:name="android.permission.INTERNET"> </uses-permission>
    <application 
                android:icon="@drawable/icon" 
                android:label="@string/app_name">
    <activity 
                android:name=".MainActivity"
                android:label="@string/app_name">
    <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
        <receiver android:name=".MainActivity">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" /> 
                <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
        </intent-filter>
        </receiver>
    </application>
    

    Hope this helps.

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

Sidebar

Related Questions

Im having some trouble writing a getstring function, this is what I have so
Im having some trouble with joining two tables. This is what my two tables
Im having some trouble with my host file.. If I change the IP for
Having some trouble with the Migrations in Sequel and could use another set of
I having some trouble figuring this problem out where I have one button which
Having some trouble with this code. Trying to return a tuple of tuples (coordinates)
Having some trouble getting this query to work correctly. mysql_query(DELETE FROM `table` WHERE `id`
I´m having some trouble deciding in which way to go... I've got this application
I'm having some trouble with this code. I am trying to write a function
having some trouble trying to figure this out, complete novice when it come to

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.