I can\'t figure out how to get the \'onReadRemoteRssi\' callback work.
My code is very simple :
final BluetoothManager bluetoothManager = (BluetoothManag
http://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi()
Async call to start reading signal strength.
http://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onReadRemoteRssi(android.bluetooth.BluetoothGatt,%20int,%20int)
Callback after the read finishes.
Need to connect before read
reference here Continual Bluetooth LE Signal Strength on Android
Put readRemoteRssi() in the callback onConnectionStateChange() of BluetoothGattCallback.
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
boolean rssiStatus = mBluetoothGatt.readRemoteRssi();
broadcastUpdate(intentAction);
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
}
}
};
And also put the onReadRemoteRssi in BluetoothGattCallback function
@Override
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status){
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, String.format("BluetoothGatt ReadRssi[%d]", rssi));
}
}
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(deviceAddress);
BluetoothGatt bluetoothGatt = getBluetoothGatt(device);
if (bluetoothGatt == null) {
return false;
}
boolean rdRemoteRssi = bluetoothGatt.readRemoteRssi();
Log.d(FTAG, "BluetoothGatt readRemoteRssi : " + rdRemoteRssi);
return true;
It will call onReadRemoteRssi call back.Need to connect before call this API.