moxy
moxy

Reputation: 93

Continual Bluetooth LE Signal Strength on Android

Can anyone suggest how to continually read BT4-LE Signal Strength on Android API Level 18+ as to detect relative proximity to BT-LE beacons? I know that LE radio signal strength is returned during scanning (see: http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback.html), but once scanning is complete and a connection is established is there anyway to get the updated BT-LE signal strength without rescanning?

Upvotes: 3

Views: 8868

Answers (3)

Hun
Hun

Reputation: 3798

if(newState == BluetoothProfile.STATE_CONNECTED) 
{
   TimerTask task = new TimerTask()
   {
      @Override
      public void run()
      {
         mBluetoothGatt.readRemoteRssi();
      }
   };
   Timer rssiTimer = new Timer();
   rssiTimer.schedule(task, 1000, 1000);
}

Upvotes: 1

Samuel C.
Samuel C.

Reputation: 111

You need to connect before you call readRemoteRssi() to read signal strength. Example code:

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
        int newState) {
    // TODO Auto-generated method stub
    String intentAction;
    if(newState == BluetoothProfile.STATE_CONNECTED) {
        intentAction = ACTION_GATT_CONNECTED;
        mConnectionState = STATE_CONNECTED;
        mBluetoothGatt.readRemoteRssi();

      

Upvotes: 0

Related Questions