filter null BT devices
This commit is contained in:
parent
9255b93800
commit
3a0d5d73f8
1 changed files with 9 additions and 11 deletions
|
@ -6,6 +6,7 @@ import android.preference.ListPreference;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
public class BluetoothDevicePreference extends ListPreference {
|
public class BluetoothDevicePreference extends ListPreference {
|
||||||
|
|
||||||
|
@ -13,25 +14,22 @@ public class BluetoothDevicePreference extends ListPreference {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
|
||||||
Integer size = 0;
|
Vector<CharSequence> entries = new Vector<CharSequence>();
|
||||||
if (bta != null) {
|
|
||||||
size += bta.getBondedDevices().size();
|
|
||||||
}
|
|
||||||
CharSequence[] entries = new CharSequence[size];
|
|
||||||
int i = 0;
|
|
||||||
if (bta != null) {
|
if (bta != null) {
|
||||||
Set<BluetoothDevice> pairedDevices = bta.getBondedDevices();
|
Set<BluetoothDevice> pairedDevices = bta.getBondedDevices();
|
||||||
for (BluetoothDevice dev : pairedDevices) {
|
for (BluetoothDevice dev : pairedDevices) {
|
||||||
entries[i] = dev.getName();
|
String name = dev.getName();
|
||||||
i++;
|
if(name != null) {
|
||||||
|
entries.add(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setEntries(entries);
|
setEntries(entries.toArray(new CharSequence[0]));
|
||||||
setEntryValues(entries);
|
setEntryValues(entries.toArray(new CharSequence[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BluetoothDevicePreference(Context context) {
|
public BluetoothDevicePreference(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue