if (devList.size() > 0)
{
String[] names = new String[devList.size()];
for (int i = 0; i < devList.size(); i++)
{
RemoteDevice btrd = ((RemoteDevice) devList.elementAt(i));
names[i] = btrd.getFriendlyName(false);
}
TextMenu searchMenu = new TextMenu(names, 1);
TextMenu subMenu = new TextMenu(new String[]{"Pair"}, 4);
int selected;
do
{
newScreen("Found");
ind.setIOMode(Indicators.IO_NONE);
selected = getSelection(searchMenu, 0);
if (selected >= 0)
{
RemoteDevice btrd = ((RemoteDevice) devList.elementAt(selected));
newScreen();
LCD.drawString(names[selected], 0, 1);
LCD.drawString(btrd.getBluetoothAddress(), 0, 2);
int subSelection = getSelection(subMenu, 0);
if (subSelection == 0)
{
newScreen("Pairing");
Bluetooth.addDevice(btrd);
byte[] tempPin =
{
'0', '0', '0', '0'
};
byte[] pin = enterNumber(4, "PIN for " + btrd.getFriendlyName(false), tempPin); // !! Assuming 4 length
if (pin == null) break;
LCD.drawString("Please wait...", 0, 6);
BTConnection connection = Bluetooth.connect(btrd.getDeviceAddr(), 0, pin);
// Indicate Success or failure:
if (connection != null)
{
LCD.drawString("Paired! ", 0, 6);
connection.close();