Use isMultipleAdvertisementSupported to check whether PeripheralManager is supported on this device, closes #83 (#85)

* Use `isMultipleAdvertisementSupported` to check whether `PeripheralManager` is supported on this device.

* 6.0.2

* 6.0.2

---------

Co-authored-by: yanshouwang <yanshouwang@outlook.com>
This commit is contained in:
渐渐被你吸引
2024-06-30 20:17:57 +08:00
committed by GitHub
parent c9f0e7e5ee
commit 78e74f7793
7 changed files with 21 additions and 11 deletions

View File

@ -111,7 +111,9 @@ class MyPeripheralManager(context: Context, binaryMessenger: BinaryMessenger) :
}
override fun getState(): MyBluetoothLowEnergyStateArgs {
val supported = context.packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)
// Use isMultipleAdvertisementSupported() to check whether LE Advertising is supported on this device before calling this method.
// See https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothAdapter#getbluetoothleadvertiser
val supported = context.packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) && adapter.isMultipleAdvertisementSupported
return if (supported) {
val authorized = permissions.all { permission -> ActivityCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED }
return if (authorized) adapter.state.toBluetoothLowEnergyStateArgs()