Skip to content

Instantly share code, notes, and snippets.

@pritam-quantum-inventions
Last active September 26, 2021 09:45
Show Gist options
  • Save pritam-quantum-inventions/30c7d307f04fe08f4646b1d9c7895cd9 to your computer and use it in GitHub Desktop.
Save pritam-quantum-inventions/30c7d307f04fe08f4646b1d9c7895cd9 to your computer and use it in GitHub Desktop.
enable bluetooth adapter
private fun bluetoothWrapper(result: MethodChannel.Result) {
val defaultAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()
if (defaultAdapter == null) {
result.error("Bluetooth adapter doesn't exist on this device", null, null)
} else {
result.success("bluetooth adapter exists on device")
}
defaultAdapter?.let {
val requestEnableBt = 1
if (!bluetoothAdapter.isEnabled) {
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableIntent, requestEnableBt)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment