AIM: To turn on and turn off wifi in android.
SOLUTION :
- Declare the following in your manifest file.
- In your Activity class
private WifiManager wifiManager;
@Override
public void onCreate(Bundle icicle) {
@Override
public void onCreate(Bundle icicle) {
// Get the Wifi service from our system
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
// Check the our wifi is currently turned on or turned off
if(wifiManager.isWifiEnabled()){
wifiManager.setWifiEnabled(false); // Turn on/off our wifi
}else{
wifiManager.setWifiEnabled(true);
}
}
wifiManager.setWifiEnabled(false); // Turn on/off our wifi
}else{
wifiManager.setWifiEnabled(true);
}
}
No comments:
Post a Comment