Question is ,Trying to create a widget for enabling and disabling the wifi.
Solving here is the solution
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
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.if(myWifiManager.isWifiEnabled()){ System.out.println("Toggle Wifi Enabled going to disable"); myWifiManager.setWifiEnabled(false); } else{ System.out.println("Wifi Disabled going to enable "); myWifiManager.setWifiEnabled(true); System.out.println("WI: "+myWifiManager.isWifiEnabled()); }
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
Get the Wifi service from our system
Reference
WifiEnabler
http://google-androidlovers.blogspot.com/2012/01/scan-for-wireless-networks-in-android.html
http://www.java2s.com/Open-Source/Android/android-platform-apps/Settings/com/android/settings/wifi/WifiApEnabler.java.htm
First you need to declare the following in your manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
</uses-permission> <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS">
</uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE">
</uses-permission> <uses-permission android:name="android.permission.WAKE_LOCK">
After doing it that on your Activity class</uses-permission>
Explanation}private WifiManager wifiManager; @Override public void onCreate(Bundle icicle) { .................... wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if(wifiManager.isWifiEnabled()){ wifiManager.setWifiEnabled(false); }else{ wifiManager.setWifiEnabled(true); }
Get the Wifi service from our system
Check the our wifi is currently turned on or turned offwifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
Turn on/off our wifi wifiManager.setWifiEnabled();if(wifiManager.isWifiEnabled()){
Reference
WifiEnabler
http://google-androidlovers.blogspot.com/2012/01/scan-for-wireless-networks-in-android.html
http://www.java2s.com/Open-Source/Android/android-platform-apps/Settings/com/android/settings/wifi/WifiApEnabler.java.htm
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
- http://www.tutorialforandroid.com/2009/10/turn-off-turn-on-wifi-in-android-using.html
- http://marakana.com/forums/android/examples/40.html
0 comments
Thanks for your comment