Android-BLE-Library: setPreferredPhy in initialize() fails on Android 13

Setting a preferred PHY in the initialize() method, fails on Android 13 (on a Pixel 4a) but works on older Android versions.

onDeviceReady() is never called on Android 13.

Setting the preferredPHY in the connect request doesn’t seem to work at all, even on older devices.

 clientManager.connect(device)
    .useAutoConnect(false)
    .usePreferredPhy(PhyRequest.PHY_LE_2M_MASK)
    .enqueue()

On older devices, I read the PHY in onDeviceReady() and it displays 2M only when setting it in initialize() not via the connectrequest.

I adapted the GattService.kt example to work with my BLE device (uses Nordic UART service). The Android 13 version receives the notifications but onDeviceReady() is not called.

I am testing with 2.5.1 on the latest commit 52d60a4de110b73faef05938ea31a699a9a38163


override fun onDeviceReady() {
    Log.i(TAG, "--------------------------------------")
    Log.i(TAG, "device is ready")
    Log.i(TAG, "--------------------------------------")
    readPhy().enqueue()
    super.onDeviceReady()
}

override fun initialize() {

    setNotificationCallback(mTXCharacteristic)
        .with { _, data ->
            if (data.value != null) {
                val value = String(data.value!!, Charsets.UTF_8)
                defaultScope.launch {
                    myCharacteristicChangedChannel?.send(value)
                }
            }
        }

    enableNotifications(mTXCharacteristic).enqueue()

    if (true && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val bluetoothManager =
            context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
        if (bluetoothManager.adapter?.isLe2MPhySupported == true) {
            setPreferredPhy(
                PhyRequest.PHY_LE_2M_MASK,
                PhyRequest.PHY_LE_2M_MASK,
                PhyRequest.PHY_OPTION_NO_PREFERRED
            ).enqueue()
        } else {
            Log.w(TAG, "PHY LE 2M not supported. Run with default 1M")
        }
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 32 (20 by maintainers)

Most upvoted comments

It seems to work on my Pixel 4a. Thanks for the fix @philips77

When will be an official release?

The issue is that the call actually succeeds, but the callback is never called…

It is printed in the log on INFO level. Swipe the services pane to the right to see the log, or select menu->Show log.

Thank you for creating the issue. We will investigate it, hopefully next week.