有人能否提供建议,如何在Android API 18+上持续读取BT4-LE信号强度以检测与BT-LE信标的相对接近程度?我知道LE无线电信号强度会在扫描期间返回(请参见:http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback.html),但一旦扫描完成并建立连接,是否有任何方法可以获得已更新的BT-LE信号强度而不需要重新扫描?
if(newState == BluetoothProfile.STATE_CONNECTED)
{
TimerTask task = new TimerTask()
{
@Override
public void run()
{
mBluetoothGatt.readRemoteRssi();
}
};
Timer rssiTimer = new Timer();
rssiTimer.schedule(task, 1000, 1000);
}
在调用readRemoteRssi()函数读取信号强度之前,需要先进行连接。 代码示例:
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();