Showing posts with label programatically enable adn disble the wifi. Show all posts
Showing posts with label programatically enable adn disble the wifi. Show all posts

Thursday 8 November 2012

turn on or off the wifi connection in android Programatically



Hello Android Guys,

This is a simple tutorial which covers following parts:
     1. Programatically  turn on or turn off the wifi connection without going to setting option
         in android. For this you have to do two things

     A. Passing Permission inside your AndroidManifest.xml file:
   <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

     B. Inside your Activity
              I. For turning off the wifi

       WifiManager wifiManager = (WifiManager)context.getSystemService
                                                                                          (Context.WIFI_SERVICE);
       wifiManager.setWifiEnabled(false); 

             II. For turning on the wifi   

        WifiManager wifiManager = (WifiManager)context.getSystemService
                                                                                                  (Context.WIFI_SERVICE);
        wifiManager.setWifiEnabled(true); 


Hope , this will Help some one.
Cheers :)
Happy Coding :)


 

Copyright @ 2013 Android Developers Blog.