Merge pull request #628 from MilosKozak/AdrianLxM-filter-null-btdevices

filter null BT devices
This commit is contained in:
Milos Kozak 2018-01-30 09:24:03 +01:00 committed by GitHub
commit 56451a67bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import android.preference.ListPreference;
import android.util.AttributeSet;
import java.util.Set;
import java.util.Vector;
public class BluetoothDevicePreference extends ListPreference {
@ -13,21 +14,18 @@ public class BluetoothDevicePreference extends ListPreference {
super(context, attrs);
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
Integer size = 0;
if (bta != null) {
size += bta.getBondedDevices().size();
}
CharSequence[] entries = new CharSequence[size];
int i = 0;
Vector<CharSequence> entries = new Vector<CharSequence>();
if (bta != null) {
Set<BluetoothDevice> pairedDevices = bta.getBondedDevices();
for (BluetoothDevice dev : pairedDevices) {
entries[i] = dev.getName();
i++;
String name = dev.getName();
if(name != null) {
entries.add(name);
}
}
setEntries(entries);
setEntryValues(entries);
}
setEntries(entries.toArray(new CharSequence[0]));
setEntryValues(entries.toArray(new CharSequence[0]));
}
public BluetoothDevicePreference(Context context) {