mirror of
https://github.com/markusfisch/BinaryEye.git
synced 2024-09-19 19:42:18 +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:
parent
a234dc3a9a
commit
a0d3b7ba87
@ -35,7 +35,14 @@ fun Scan.sendBluetoothAsync(
|
||||
}
|
||||
|
||||
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 {
|
||||
it.name
|
||||
}.toTypedArray()
|
||||
|
Loading…
Reference in New Issue
Block a user