how to get the rssi value for a bluetooth low energy device ?

19,060

Two solution for this.There is different approach one can have for 4.0 and 5.0 devices to search/scan BLE devices. You did not mentioned which one you are using, hence adding both the solution below.

1) for Android 4.4 + till 5.0, you have to start LE scanning via BluetoothAdapter's startLEScan method, which gives you below callback with RSSI value. see signature of method.

onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)

// second param above is RSSI value.

2) For android 5.0+ devices you have to start scanning by BluetoothLeScanner class's startScan method, like below

getBluetoothLeScanner().startScan

which has callback onScanResult to notify for new scanned device, you can use below code to get rssi.

public void onScanResult(int callbackType, ScanResult result) {
final int rssi = result.getRssi(); //RSSI value
Share:
19,060
alaa
Author by

alaa

Updated on June 13, 2022

Comments

  • alaa
    alaa about 2 years

    I am new with android programming and trying to get rssi value form a BLE device for distance measurements.i can scan and get the name and mac address of the device but i've tried codes to get the rssi but can't get useful result,also i use the sample on the android developer site. can someone give me the right code to do so??

  • alaa
    alaa about 9 years
    i am using android 4.3 , i used the first solution and it work probably. thank you !
  • AAnkit
    AAnkit about 9 years
    @alaa, RSSI comes in - value, from -100 to 0. if it works for you, you can accept the answer.
  • Mr. Unnormalized Posterior
    Mr. Unnormalized Posterior almost 7 years
    @AAnkit can you please share a working code? Thank you.