public void run() { LogManager.d(BluetoothMedic.TAG, "Turning Bluetooth back on."); if (BluetoothMedic.this.mAdapter != null) { BluetoothMedic.this.mAdapter.enable(); } } }, 1000L);
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; }
@Test public void canEnable_withAndroidApi() throws Exception { bluetoothAdapter.enable(); assertThat(bluetoothAdapter.isEnabled()).isTrue(); }
if(!bluetoothAdapter.isEnabled()) bluetoothAdapter.enable(); Log.i("Log", "Bluetooth is Enabled");
/** * Request for enable the device's bluetooth asynchronously. * Throw a NullPointerException if the device doesn't have a bluetooth module. */ public void requestEnableBt() { if (mBluetoothAdapter == null) { throw new NullPointerException(DEVICE_HAS_NOT_BLUETOOTH_MODULE); } if (!mBluetoothAdapter.isEnabled()) mBluetoothAdapter.enable(); }
@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 on the local Bluetooth adapter — do not use without explicit user action to turn on * Bluetooth. * * @return true to indicate adapter startup has begun, or false on * immediate error * @see BluetoothAdapter#enable() */ public boolean enable() { return bluetoothAdapter.enable(); }
@Override public void run() { mBluetoothAdapter.enable(); Log.e(TAG, "Cycling BT-gatt - enableing BT"); cycling_bt = false; } }, 3000);
public void enableBT(View view){ BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()){ mBluetoothAdapter.enable(); } }
@Override public void run() { try { if (mBluetoothAdapter != null) mBluetoothAdapter.enable(); } catch (SecurityException e) { JoH.static_toast_short("Please enable Bluetooth!"); } } }, 1000);
@Override public void run() { mBluetoothAdapter.enable(); Log.e(TAG, "Cycling BT-gatt - enableing BT"); cycling_bt = false; } }, 3000);
@Override public void run() { try { if (mBluetoothAdapter != null) mBluetoothAdapter.enable(); } catch (SecurityException e) { JoH.static_toast_short("Please enable Bluetooth!"); } } }, 1000);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); Thread.sleep(500); //code for dealing with InterruptedException not shown mBluetoothAdapter.enable(); }
private void forceTurnOnBluetooth() { final boolean open = mAdapter.isEnabled() || mAdapter.enable(); mShouldOpen = true; if (!open) { showSystemTurnOnBluetoothDialog(); } }
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { //deatctivate bluetooth mBluetoothAdapter.disable(); } //Activate bluetooth mBluetoothAdapter.enable();
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if(adapter != null) { if(adapter.getState() == BluetoothAdapter.STATE_ON) { adapter.disable(); } else if (adapter.getState() == BluetoothAdapter.STATE_OFF){ adapter.enable(); } else { //State.INTERMEDIATE_STATE; } }
public void changeState() { if (available()) { if (adapter.getState() == BluetoothAdapter.STATE_OFF) { adapter.enable(); } else if (adapter.getState() == BluetoothAdapter.STATE_ON) { adapter.disable(); } } }