Reputation: 93
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
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
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
Reputation: 1829
http://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi()
Async call to start reading signal strength.
Callback after the read finishes.
Need to connect before read.
Upvotes: 9