0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-20 03:52:16 +02:00

Catch SecurityExc when BT permission is missing

Make sure not to crash the app because the bluetooth permission is
missing. The app should gracefully handle this situation. It's
perfectly okay when the app doesn't have the permission to use
bluetooth. This is really a very niche use-case.
This commit is contained in:
Markus Fisch 2023-03-27 21:24:29 +02:00
parent a234dc3a9a
commit a0d3b7ba87

View File

@ -35,7 +35,14 @@ fun Scan.sendBluetoothAsync(
} }
fun setBluetoothHosts(listPref: ListPreference) { fun setBluetoothHosts(listPref: ListPreference) {
val devices = BluetoothAdapter.getDefaultAdapter().bondedDevices val devices = try {
BluetoothAdapter.getDefaultAdapter().bondedDevices
} catch (e: SecurityException) {
// Do nothing, either the user has denied Bluetooth access
// or the permission was removed by the system. We're catching
// the exception to keep the app from crashing.
null
} ?: return
listPref.entries = devices.map { listPref.entries = devices.map {
it.name it.name
}.toTypedArray() }.toTypedArray()