filter null BT devices
This commit is contained in:
parent
9255b93800
commit
3a0d5d73f8
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue