我正在尝试查找范围内所有可用的蓝牙设备,但是我只得到了一个设备。我在线程中使用它,在run方法中。我已经在网上检查了很多链接来解决这个问题,但是无法解决该问题。 这是我的代码
public void run() {
if(service != null) {
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
service.registerReceiver(this.bReceiver, filter);
bluetooth.startDiscovery();
}
}
class BluetoothReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Set<BluetoothDevice> pairedDevices = bluetooth.getBondedDevices();
String action = intent.getAction();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
Log.d(TAG, device.getName());
}
}
if(BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String uuid = intent.getStringExtra(BluetoothDevice.EXTRA_UUID);
int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
Log.d(TAG, device.getName());
}
}
}
此外,我希望能够获取每个找到设备的RSSI值,但请忽略语法。