In Delphi FMX 10.3, I can scan for a BLE device and can connect to it, and can also receive data, but when sending data more than 20 bytes, the app cannot receive data. I know modifying the MTU to greater than 20 will work ok.
In Android Studio, it is easy to implement, but in Delphi FMX I cannot find any support.
Android Studio sample:
private void setMtu(int setMtu) {
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
bluetoothAdapter.startLeScan(new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
device.connectGatt(DemoActivity.this, true, new BluetoothGattCallback() {
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (setMtu > 23 && setMtu < 512) {
gatt.requestMtu(setMtu);
}
}
}
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
mMtu = mtu;
if (BluetoothGatt.GATT_SUCCESS == status && setMtu == mtu) {
LogUtils.d("MTU change success = " + mtu);
} else {
LogUtils.d("MTU change fail!");
}
}
});
}
});
}
But in Delphi, how to implement this?