setPreferredPhy in initialize() fails on Android 13
See original GitHub issueSetting 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 connect
request.
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")
}
}
}
Issue Analytics
- State:
- Created a year ago
- Comments:30 (20 by maintainers)
Top Results From Across the Web
BluetoothGattCharacteristic > write crashes with Android 13
If the Bluetooth service is crashing when you write a characteristic, it's a bug in the Bluetooth stack which you should report to...
Read more >Android-BLE-Library/BleManagerHandler.java at main - GitHub
A library that makes working with Bluetooth LE on Android a pleasure. Seriously. ... Flag set to true when the initialization queue is...
Read more >BluetoothGatt - Android Developers
A GATT operation failed, errors other than the above ... void, setPreferredPhy(int txPhy, int rxPhy, int phyOptions) ... Constant Value: 13 (0x0000000d) ...
Read more >Diff - platform/frameworks/base - Google Git
Merge "DeviceInfoUtils.java: support to show kernel version compiled with clang" diff --git a/api/current.txt b/api/current.txt index c095202..71df2e0 ...
Read more >Android 13: Unable to reconnect reliably to bonded peripheral
Ever since the Android 13 beta, we've observed Android 13 being very inconsistent with reconnection behavior when it comes to bonded Bluetooth Low...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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…