Merge pull request #628 from MilosKozak/AdrianLxM-filter-null-btdevices
filter null BT devices
This commit is contained in:
commit
56451a67bf
|
@ -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,25 +14,22 @@ 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) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue