requestPreferredPhy method

  1. @override
Future<void> requestPreferredPhy({
  1. required String deviceAddress,
  2. required BlePhy txPhy,
  3. required BlePhy rxPhy,
})
override

Requests a preferred PHY for the connection to the specified device.

On Android, this calls BluetoothGatt.setPreferredPhy (API 26+). The actual PHY applied depends on what the remote device supports. On iOS, the call succeeds silently because PHY negotiation is handled by the OS.

Implementation

@override
Future<void> requestPreferredPhy({
  required String deviceAddress,
  required BlePhy txPhy,
  required BlePhy rxPhy,
}) async {
  try {
    await channel.invokeMethod('requestPreferredPhy', {
      'address': deviceAddress,
      'txPhy': txPhy.identifier,
      'rxPhy': rxPhy.identifier,
    });
  } on PlatformException catch (e) {
    throw BluetoothConnectionException(
      'Failed to request preferred PHY: ${e.message}',
    );
  }
}