diff --git a/androidgcs/src/org/openpilot/androidgcs/BluetoothDevicePreference.java b/androidgcs/src/org/openpilot/androidgcs/BluetoothDevicePreference.java new file mode 100644 index 000000000..8f0905fa8 --- /dev/null +++ b/androidgcs/src/org/openpilot/androidgcs/BluetoothDevicePreference.java @@ -0,0 +1,33 @@ +package org.openpilot.androidgcs; + +import android.bluetooth.*; +import android.content.Context; +import android.preference.ListPreference; +import android.util.AttributeSet; + +import java.util.Set; + +public class BluetoothDevicePreference extends ListPreference { + + public BluetoothDevicePreference(Context context, AttributeSet attrs) { + super(context, attrs); + + BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter(); + Set pairedDevices = bta.getBondedDevices(); + CharSequence[] entries = new CharSequence[pairedDevices.size()]; + CharSequence[] entryValues = new CharSequence[pairedDevices.size()]; + int i = 0; + for (BluetoothDevice dev : pairedDevices) { + entries[i] = dev.getName(); + entryValues[i] = dev.getAddress(); + i++; + } + setEntries(entries); + setEntryValues(entryValues); + } + + public BluetoothDevicePreference(Context context) { + this(context, null); + } + +} \ No newline at end of file diff --git a/androidgcs/src/org/openpilot/androidgcs/BluetoothUAVTalk.java b/androidgcs/src/org/openpilot/androidgcs/BluetoothUAVTalk.java index c00db0bea..b2c622238 100644 --- a/androidgcs/src/org/openpilot/androidgcs/BluetoothUAVTalk.java +++ b/androidgcs/src/org/openpilot/androidgcs/BluetoothUAVTalk.java @@ -99,8 +99,9 @@ import android.util.Log; for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a ListView //mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); - Log.d(TAG, "Paired device: " + device.getName()); - if(device.getName().compareTo(device_name) == 0) { + Log.d(TAG, "Paired device: " + device.getAddress() + " compared to " + device_name); + if(device.getAddress().compareTo(device_name) == 0) { + Log.d(TAG, "Found device: " + device.getName()); this.device = device; return; } @@ -110,7 +111,7 @@ import android.util.Log; } private boolean openTelemetryBluetooth(UAVObjectManager objMngr) { - Log.d(TAG, "Opening conncetion to " + device.getName()); + Log.d(TAG, "Opening connection to " + device.getName()); socket = null; connected = false; try {