Android Projects

Android Development Books


WiFi state is not enabling so how to fix it?

Question is ,Trying to create a widget for enabling and disabling the wifi.
            System.out.println("Toggle Wifi Enabled going to disable");
            System.out.println("Wifi Disabled going to enable ");

            System.out.println("WI: "+myWifiManager.isWifiEnabled());
This is the code i am using the disabling part is working fine but the enabling part is not working fine. Soon after enabling the wifi i am printing the wifi state i am getting it as false.

Solving here is the solution

Here is how to turn on and turn off wifi in android.
First you need to declare the following in your manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS">

<uses-permission android:name="android.permission.CHANGE_WIFI_STATE">

<uses-permission android:name="android.permission.WAKE_LOCK">

After doing it that on your Activity class
private WifiManager wifiManager;
@Override public void onCreate(Bundle icicle) {
 wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
Get the Wifi service from our system
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
Check the our wifi is currently turned on or turned off
Turn on/off our wifi wifiManager.setWifiEnabled();


Or May this

After wifiManager.setWifiEnabled(true); 
it took few seconds to connect to the network. It seems WifiManager reconnects automatically after call to wifiManager.setWifiEnabled(true

Dont forget this also

Finally goto more deatils problem and solution in stackoverflow. go to[android]+wifi
Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...


Thanks for your comment

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

Related Posts Plugin for WordPress, Blogger...
© Google Android Lovers
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0