Skip to content

Instantly share code, notes, and snippets.

@melihmucuk
Created October 1, 2013 22:11
Show Gist options
  • Select an option

  • Save melihmucuk/6785984 to your computer and use it in GitHub Desktop.

Select an option

Save melihmucuk/6785984 to your computer and use it in GitHub Desktop.
Programmatically Bluetooth On/Off on Android
boolean BluetoothOnOff(boolean status, Context context) {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
.getDefaultAdapter();
try {
if (status) {
if (!mBluetoothAdapter.isEnabled()) {
mBluetoothAdapter.enable();
}
} else {
if (mBluetoothAdapter.isEnabled()) {
mBluetoothAdapter.disable();
}
}
return true;
} catch (Exception e) {
Log.e("Bluetooth", "error turning on/off bluetooth");
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment