2

I've implemented a list with all of my paired devices, and now I'd like to know if it's possible to connect to some of them only with clicking on the item.

For example if my list contains a bluetooth device called X and I want to connect to it (with my app) click on it and the connection is stablished between device and my phone.

This is how I list my paired devices :

 myListView = (ListView) dialog.findViewById(R.id.BTList);
    BTArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    myListView.setAdapter(BTArrayAdapter);
    pairedDevices = myBluetoothAdapter.getBondedDevices();
    for(BluetoothDevice device : pairedDevices)
        BTArrayAdapter.add(device.getName()+ "\n" + device.getAddress());
9
  • This might help you. stackoverflow.com/questions/11292441/… Commented Feb 25, 2016 at 12:28
  • I need more details this answer is too much explained Commented Feb 25, 2016 at 12:34
  • if you success please post solution for connect to specific paired device. Commented Feb 25, 2016 at 12:38
  • @AjayPandya What do you mean? Commented Feb 25, 2016 at 12:39
  • I'm also looking for the scenario Commented Feb 25, 2016 at 12:40

1 Answer 1

1

If you know the name of the device you wish to pair to you can use an equals comparison.

private static final String DEVICE_WE_WANT_TO MATCH = "X";

String devName = device.getName();
if(devName.equals(DEVICE_WE_WANT_TO MATCH)){
    // Connect.
}

You can also use an app UUID

private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

This will mean that only devices using this UUID will connect using your protocol, it's an extra layer of security for the app.

In this, latter, case, we're relying on one android device to be acting as a BT server and the other as a BT client.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm gonna test it, but I asked it to know how to connect, the list I allready showed up... but thanks anyways for the reply ;)
If you have time/and you want me to show how to connect programmatically, go ahead, your help is always welcome :D
Hi @Yvette Colomb, maybe you can help me out on this question? Big price on it :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.