问题
I am working on App which is communicate with BLE device.I can write 20 bytes easily on characteristics but when it is more than 20 bytes it's create problem.I am using
mBluetoothGatt.requestMtu(512);
write charateristics after getting success.
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
if (status == BluetoothGatt.GATT_SUCCESS) {
System.out.print("Mtu Granted");
// this.supportedMTU = mtu;
}
}
which is working fine in marshmallow and lolipop.But it is not working in Nougat(Samsung galaxy s6).
回答1:
I was having this exact same issue, so I put the mtu request in a loop and it seems to work after 2 attempts regularly.
new Thread(new Runnable() {
@Override
public void run() {
while (!mtuConfirmed) {
mBluetoothGatt.requestMtu(512);
mtuRequestCounter++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Log.d(TAG, "MTU change reply received after " + mtuRequestCounter + " attempts");
}
}).start();
来源:https://stackoverflow.com/questions/46149114/request-mtu-is-not-working-in-nougat