3

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

4

3 回答 3

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);
}
于 2014-01-03T07:16:44.430 回答
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();

      

于 2013-11-27T07:51:47.417 回答