Próbuję znaleźć wszystkie dostępne urządzenia Bluetooth w zakresie. Ale otrzymuję tylko jedno urządzenie, którego używam w metodzie wątek w uruchomieniu. Sprawdziłem już wiele linków dla tego problemu, ale nie mogłem rozwiązać tego problemu. Oto mój kodJak znaleźć dostępne urządzenia Bluetooth w zasięgu?
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());
}
}
}
Ponadto chcę RSSI wartości każdego znalezionego urządzenia, ale proszę ignorować składnię
Ale jeśli widzisz mój kod ... to jest taki sam jak twój. ..i nie widzę żadnej różnicy, dlaczego mój kod nie działa –
Co dokładnie nie działa w twoim kodzie? Czy nazywa się onReceive (...)? –
Problem polega na tym, że aplikacja się zawiesza po dotarciu do tego odbiornika nie wiem dlaczego i innym poważnym problemem jest to, że dostaję tylko jedno aktywne urządzenie bluetooth zamiast tego, że chcę wszystkie dostępne aktywne urządzenia bluetooth ... –