//Disable bluetooth BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); }
public static boolean setBluetooth(boolean enable) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); boolean isEnabled = bluetoothAdapter.isEnabled(); if (enable && !isEnabled) { return bluetoothAdapter.enable(); } else if(!enable && isEnabled) { return bluetoothAdapter.disable(); } // No need to change bluetooth state return true; }
@RequiresApi(21) private void cycleBluetooth() { LogManager.d(TAG, "Power cycling bluetooth"); LogManager.d(TAG, "Turning Bluetooth off."); if (mAdapter != null) { this.mAdapter.disable(); this.mHandler.postDelayed(new Runnable() { public void run() { LogManager.d(BluetoothMedic.TAG, "Turning Bluetooth back on."); if (BluetoothMedic.this.mAdapter != null) { BluetoothMedic.this.mAdapter.enable(); } } }, 1000L); } else { LogManager.w(TAG, "Cannot cycle bluetooth. Manager is null."); } }
@Test public void canDisable_withAndroidApi() throws Exception { shadowBluetoothAdapter.setEnabled(true); bluetoothAdapter.disable(); assertThat(bluetoothAdapter.isEnabled()).isFalse(); }
if(bluetoothAdapter.isEnabled()) bluetoothAdapter.disable();
@Override public void onCheckedChanged(CompoundButton button, boolean isChecked) { if (isChecked) { bluetoothAdapter.enable(); } else { bluetoothAdapter.disable(); } } });
@SuppressLint("DefaultLocale") public static void onBlueTooth(String action) { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter .getDefaultAdapter(); if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("on")) { if (!mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.enable(); } } if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("off")) { if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); } } }
@SuppressLint("DefaultLocale") public static void onBlueTooth(String action) { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter .getDefaultAdapter(); if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("on")) { if (!mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.enable(); } } if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("off")) { if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); } } }
/** * 设置蓝牙状态 * * @param enable * 打开 * 没有找到蓝牙设备 */ public static void setBluetooth(boolean enable) throws Exception { // 如果当前蓝牙的状态与要设置的状态不一样 if (isBluetoothOpen() != enable) { // 如果是要打开就打开,否则关闭 if (enable) { BluetoothAdapter.getDefaultAdapter().enable(); } else { BluetoothAdapter.getDefaultAdapter().disable(); } } }
/** * Turn off the local Bluetooth adapter — do not use without explicit user action to turn off * Bluetooth. * * @return true to indicate adapter shutdown has begun, or false on * immediate error * @see BluetoothAdapter#enable() */ public boolean disable() { return bluetoothAdapter.disable(); }
public void disableBT(View view){ BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()){ mBluetoothAdapter.disable(); } }
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { //Play with bluetooth }else{ mBluetoothAdapter.disable(); }
@Override public void Disable() { try { mBluetoothAdapter.disable(); } catch (Exception e) { sendMessageToUI_Toast("Can't disable BT"); } }
/******************************************************************************** * Stop listening for Intents as soon as activity gets destroyed *******************************************************************************/ @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(receiver); mBluetoothAdapter.disable(); }
private void bluetoothOff(View view){ mBTAdapter.disable(); // turn off mBluetoothStatus.setText("Bluetooth disabled"); Toast.makeText(getApplicationContext(),"Bluetooth turned Off", Toast.LENGTH_SHORT).show(); }
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); Thread.sleep(500); //code for dealing with InterruptedException not shown mBluetoothAdapter.enable(); }
public static boolean setBluetooth(boolean enable) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); boolean isEnabled = bluetoothAdapter.isEnabled(); if (enable && !isEnabled) { return bluetoothAdapter.enable(); } else if(!enable && isEnabled) { return bluetoothAdapter.disable(); } // No need to change bluetooth state return true; }
public static void stopBluetooth() { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { if (bluetoothAdapter.isEnabled()) { bluetoothAdapter.disable(); } } }
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); wifiManager.setWifiEnabled(false); boolean wifiEnabled = wifiManager.isWifiEnabled(); //Disable bluetooth BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); }
public void changeState() { if (available()) { if (adapter.getState() == BluetoothAdapter.STATE_OFF) { adapter.enable(); } else if (adapter.getState() == BluetoothAdapter.STATE_ON) { adapter.disable(); } } }