2011-01-26 02:35:38 +00:00
|
|
|
package de.duenndns;
|
|
|
|
|
|
|
|
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);
|
2011-09-13 18:23:06 +00:00
|
|
|
}
|
2011-01-26 02:35:38 +00:00
|
|
|
|
2011-09-13 18:23:06 +00:00
|
|
|
protected void onPrepareDialogBuilder(android.app.AlertDialog.Builder builder) {
|
|
|
|
// hook into the builder to refresh the list
|
2011-01-26 02:35:38 +00:00
|
|
|
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
|
2014-12-20 16:28:31 +00:00
|
|
|
Set<BluetoothDevice> pairedDevices = (bta != null) ? bta.getBondedDevices() : null;
|
|
|
|
if (pairedDevices == null) {
|
|
|
|
super.onPrepareDialogBuilder(builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-26 02:35:38 +00:00
|
|
|
CharSequence[] entries = new CharSequence[pairedDevices.size()];
|
|
|
|
CharSequence[] entryValues = new CharSequence[pairedDevices.size()];
|
|
|
|
int i = 0;
|
|
|
|
for (BluetoothDevice dev : pairedDevices) {
|
2016-09-08 16:41:10 +00:00
|
|
|
if (dev.getAddress() != null) {
|
|
|
|
entries[i] = dev.getName();
|
|
|
|
if (entries[i] == null)
|
|
|
|
entries[i] = "(null)";
|
|
|
|
entryValues[i] = dev.getAddress();
|
|
|
|
i++;
|
|
|
|
}
|
2011-01-26 02:35:38 +00:00
|
|
|
}
|
|
|
|
setEntries(entries);
|
|
|
|
setEntryValues(entryValues);
|
2011-09-13 18:23:06 +00:00
|
|
|
|
|
|
|
super.onPrepareDialogBuilder(builder);
|
2011-01-26 02:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public BluetoothDevicePreference(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|