Is it possible to disable wireless networking on an Android device using the Android SDK or NDK?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
In order to enable / disable the WiFi state, you have to grant the following permission in the application manifest
android.permission.CHANGE_WIFI_STATE
You can then use the WifiManager to set enable/disable the WIFI.
WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(enabled);
More info on http://developer.android.com/reference/android/net/wifi/WifiManager.html
For a complete sample, check the following post : http://android-er.blogspot.com/2011/01/turn-wifi-onoff-using.html
回答2:
Yes you can disable the wifi programmatically:
- Retrieve a WifiManager object from
Context.getSystemService(Context.WIFI_SERVICE)
- Set setWifiEnabled to true or false as you wish
Look up for the permission settings. You will probably need to add some in the AndroidManifest.xml