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 :)


Mukesh Yadav

Hi Guys I am from Delhi working as Web/Mobile Application Developer(Android Developer), also have knowledge of Roboelctric and Mockito ,android test driven development... Blogging has been my passion and I think blogging is one of the powerful medium to share knowledge and ideas....

0 comments:

Post a Comment

 

Copyright @ 2013 Android Developer Blog.

Blog Widget by LinkWithin