fix: CompanionDeviceManager.EXTRA_DEVICE return types

This commit is contained in:
andrekir 2023-12-04 21:11:18 -03:00
parent c9ecb2fe90
commit ac63e72233

View file

@ -2,6 +2,7 @@ package com.geeksville.mesh.util
import android.app.PendingIntent
import android.bluetooth.BluetoothDevice
import android.bluetooth.le.ScanResult
import android.companion.AssociationInfo
import android.companion.CompanionDeviceManager
import android.content.Intent
@ -46,8 +47,11 @@ fun Intent.getAssociationResult(): String? = when {
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O ->
@Suppress("DEPRECATION")
getParcelableExtra<BluetoothDevice>(CompanionDeviceManager.EXTRA_DEVICE)
?.address
when (val it = getParcelableExtra<Parcelable>(CompanionDeviceManager.EXTRA_DEVICE)) {
is BluetoothDevice -> it.address
is ScanResult -> it.device.address
else -> null
}
else -> null
}