Course Content

Course Content

Wifi Example in Android

Creating Android Application for Wi-Fi

 

In this video we are going to create an application for better understanding of Wi-Fi in Android.

First of all we need to provide certain permissions in AndroidManifest.xml file such as ACCESS_WIFI_STATE, INTERNET, CHANGE_WIFI_STATE.

Now in our activity_main.xml file, we will take two buttons, one to enable Wi-Fi another to disable Wi-Fi.

After that in MainActivity.java file we will do view identification of the buttons which we have taken.

enableButton=(Button)findViewById(R.id.button1);

disableButton=(Button)findViewById(R.id.button2);

Next step is to design listener for both the buttons.

enableButton.setOnClickListener(new onClickListener() {

public void onClick(View v) {

WifiManager wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);

wifi.setWifiEnabled(true);

}};

disableButton.setOnClickListener(new onClickListener() {

public void onClick(View v) {

WifiManager wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);

wifi.setWifiEnabled(false);

}};

After that we will run our code, it will run successfully. Our device will get connected to a Wi-Fi when click on enable Wi-Fi button.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere