Wifi開啟及狀態偵測
首先需要在Manifest.xml 加入以下三個permission
然後在程式內加入
private WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE)
if (wifiManager.isWifiEnabled()) //判斷目前wifi狀態 開啟會回傳true
wifiManager.setWifiEnabled(false); //把wifi關閉
else
wifiManager.setWifiEnabled(true); //把wifi開啟
bluetooth開啟及狀態偵測
首先需要在Manifest.xml 加入以下兩個permission
然後在程式內加入
private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter.isEnabled())\\判斷目前bluetooth狀態 開啟會回傳true
mBluetoothAdapter.disable(); //將bluetooth關閉
else
mBluetoothAdapter.enable(); //將buletooth開啟
參考網頁http://goo.gl/A6anzN
http://goo.gl/11Qi7Y
http://goo.gl/Slssm
http://goo.gl/xgLsp
沒有留言:
張貼留言