Android上的持续蓝牙LE信号强度

时间:2013-09-05 00:16:29

标签: android bluetooth bluetooth-lowenergy

有人可以建议如何在Android API Level 18+上持续读取BT4-LE信号强度,以检测BT-LE信标的相对接近度?我知道在扫描过程中会返回LE无线电信号强度(参见:http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback.html),但是一旦完成扫描并建立了连接,无论如何都要获得更新的BT-LE信号强度而不重新扫描?

3 个答案:

答案 0 :(得分:9)

答案 1 :(得分:1)

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

答案 2 :(得分:0)

在调用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();