获取Android显式配对设备的RSSI值
我已经通过应用程序将我的设备与Android手机明确配对。此设备为MI波段2,使用MI-FIT应用程序配对。我当前正在使用以下代码连接蓝牙设备:获取Android显式配对设备的RSSI值,android,bluetooth,Android,Bluetooth,我已经通过应用程序将我的设备与Android手机明确配对。此设备为MI波段2,使用MI-FIT应用程序配对。我当前正在使用以下代码连接蓝牙设备: String action = intent.getAction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXT
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-fit应用程序连接,我无法从MI波段获取RSSI值
有没有可能在Android中获得显式配对设备的RSSI值?如果是,我做错了什么
谢谢
编辑:似乎我无法获取任何连接设备的RSSI值。例如,如果Android phone A连接到Android phone B,那么我在尝试通过上述代码从phone A读取时无法读取RSSI值。如果您确实知道要连接的设备的蓝牙名称,也许您可以尝试使用以在扫描时引起注意。或者你真的需要区分扫描或连接吗
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());
}
};