filter null BT devices

This commit is contained in:
AdrianLxM 2018-01-30 01:02:21 +01:00 committed by GitHub
parent 9255b93800
commit 3a0d5d73f8
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) {