From 3a0d5d73f8215a86650bdb26ee83cce90c037db0 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 30 Jan 2018 01:02:21 +0100 Subject: [PATCH] filter null BT devices --- .../PumpDanaR/BluetoothDevicePreference.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java index 63e14f0921..e39fdcfdaa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java @@ -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 entries = new Vector(); if (bta != null) { Set 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); } -} \ No newline at end of file +}