Prevent crash if bluetooth isn't available on the device

This commit is contained in:
Sylvain Berfini 2022-01-19 12:24:17 +01:00
parent 17547753b4
commit 8dfbe98396
2 changed files with 4 additions and 2 deletions

View file

@ -48,7 +48,8 @@ class Api21Compatibility {
companion object {
@SuppressLint("MissingPermission")
fun getDeviceName(context: Context): String {
var name = BluetoothAdapter.getDefaultAdapter().name
val adapter = BluetoothAdapter.getDefaultAdapter()
var name = adapter?.name
if (name == null) {
name = Settings.Secure.getString(
context.contentResolver,

View file

@ -34,7 +34,8 @@ class Api25Compatibility {
context.contentResolver, Settings.Global.DEVICE_NAME
)
if (name == null) {
name = BluetoothAdapter.getDefaultAdapter().name
val adapter = BluetoothAdapter.getDefaultAdapter()
name = adapter?.name
}
if (name == null) {
name = Settings.Secure.getString(