How to enable or disable Wifi in android programmatically

In this post, we will see how to enable or disable Wifi in android programmatically.
It is very simple to enable or disable wifi from android code.
For enabling WiFi:
For disabling Wifi:
So you can enable or disable WiFi using WifiManger class.
You need to add extra permissions in AndroidManifest.xml to enable or disable Wifi.

Source code:

Step 1 :

Create an android application project named “EnableDisableWiFiApp”.

Step 2:

Add following permissions in AndoridManifest.xml.

Go to app -> src -> main -> AndroidManifest.xml and add above permissions. AndroidManifest.xml will look like below xml.

Step 3 :

Change res ->layout -> activity_main.xml as below:

Step 4:

Change src/main/packageName/MainActivity.java as below:

Step 5:

Run the app
When you run the app, you will get below screen:

When you click on toggle button, you will get below screen:

Related Posts

  • Check if variable is String in Python
    13 January

    Check if variable is String in python

    Table of ContentsHow to check if a given variable is of the string type in Python?Using the isinstance() function.Using the type() function.Check if function parameter is String In this post, we will see what is a string in Python and how to check whether a given variable is a string or not. There are many […]

  • Check if input is Integer in C++
    13 January

    Check If Input Is Integer In C++

    Table of ContentsHow to Check Whether the Input Is an Integer in C++?Check Whether the Input Is an Integer Using the isdigit() Function in C++Check Whether the Input Is an Integer Using the Ascii Values in C++Conclusion C++ is a powerful and popular programming language and we use it widely in coding applications. It provides […]

  • Count the number of characters in a String in Python
    13 January

    Count number of characters in a string in python

    Table of ContentsWays to count the number of characters in a string in PythonUsing the len() functionUsing the for loopUsing the collections.Counter classConclusion In this post, we will see how to count number of characters in a String in Python. We can think of strings as a collection of characters, with every character at a […]

  • Pandas apply function to column
    12 January

    Pandas apply function to column

    Table of ContentsHow do I apply function to column in pandas?Using dataframe.apply() functionUsing lambda function along with the apply() functionUsing dataframe.transform() functionUsing map() functionUsing NumPy.square() function We make use of the Pandas dataframe to store data in an organized and tabular manner. Sometimes there, is a need to apply a function over a specific column […]

  • Copy file Python
    12 January

    How to Copy File in Python?

    Table of ContentsCopy file using the shutil module in PythonCopy file using the copyfileobj() function in PythonCopy file using the copyfile() function in PythonCopy file using the copy() function in PythonCopy file using the copy2() function in PythonCopy file using the operating system command in PythonCopy file using the os module in PythonCopy file using […]

  • Find rows with nan in Pandas
    11 January

    Find rows with nan in Pandas

    Table of ContentsWhat is nan values in Pandas?Find rows with NAN in pandasFind columns with nan in pandasFind rows with nan in Pandas using isna and iloc() In this post, we will see how to find rows with nan in Pandas. What is nan values in Pandas? A pandas DataFrame can contain a large number […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.