Skip to content

Instantly share code, notes, and snippets.

@bdivljak91
Last active August 27, 2019 12:04
Show Gist options
  • Save bdivljak91/07ef8c80033e5ae28627d63f8943c650 to your computer and use it in GitHub Desktop.
Save bdivljak91/07ef8c80033e5ae28627d63f8943c650 to your computer and use it in GitHub Desktop.
Simple Bluetooth state monitor broadcast receiver
private val broadCastReceiver = object : BroadcastReceiver() {
override fun onReceive(contxt: Context?, intent: Intent?) {
val action = intent?.action
if (action == BluetoothAdapter.ACTION_STATE_CHANGED) {
val state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
when (state) {
BluetoothAdapter.STATE_OFF -> setUIBluetoothOff()
BluetoothAdapter.STATE_ON -> setUIBluetoothOn()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment