Я ищу в диапазоне доступных Bluetooth devices
.По какой-то причине каждое найденное устройство добавляется в ListView дважды , когда оно должно отображаться только один раз .
Кто-нибудь знает, что я здесь не так делаю?Код, указанный ниже.
Когда обнаружение обнаружит устройство
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device;
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// If it's already paired, skip it, because it's been listed already
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
Log.v("test", "test");
mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
// When discovery is finished, change the Activity title
setProgressBarIndeterminateVisibility(false);
setTitle(R.string.select_device);
if (mNewDevicesArrayAdapter.getCount() == 0) {
String noDevices = getResources().getText(R.string.none_found).toString();
mNewDevicesArrayAdapter.add(noDevices);
}
}