2017-07-07 15 views
1

私のデバイスをAndroidの携帯電話に明示的に、アプリケーション経由でペアリングしました。このデバイスはMI-Band 2で、MI-FITアプリを使用してペアになっています。私は現在、このコードを使用してBluetoothデバイスに接続しています:AndroidのRSSI値を取得する明示的にペア設定されたデバイス

String action = intent.getAction(); 
     if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
      int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE); 

しかし、問題はMI-バンドはMI-フィットアプリを介して接続されている場合、私はMI-バンドからRSSI値を得ることができないということです。

明示的にペア設定されたデバイスのRSSI値をAndroidで取得することはできますか?もしそうなら、私は間違って何をしていますか?

おかげ

編集を:私はすべての接続されたデバイスのRSSI値を得ることができないように思えます。たとえば、Android phone AがAndroid Phone Bに接続されている場合、電話機Aから上記のコードを読み取ろうとすると、RSSI値を読み取ることができません。

答えて

1

デバイスのBluetooth名が接続されている場合は、BluetoothAdapter.LeScanCallbackを使用してスキャン時に気付くようにしてください。それとも、スキャンしたり、別の場所に接続する必要がありますか?

BluetoothManager bleManager = (BluetoothManager) getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE); 
BluetoothAdapter bleAdapter = bleManager.getAdapter(); 
bleAdapter.startLeScan(leScanCallback);// find match device 
BluetoothAdapter.LeScanCallback leScanCallback = new BluetoothAdapter.LeScanCallback() { 

     @Override 
     public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) { 
      if (device.getName() == null || !device.getName().equals("your bluetooth device name")) { 
       return; 
      } 
      // here you can get rssi of specified bluetooth device if it's available. 
      // and try to connect it programmatically. 
      connect(device.getAddress()); 
     } 
    }; 
関連する問題