0

I was trying to create a personal app that easily toggles any bluetooth device that I am paired to. I was able to get BluetoothDevice set from BluetoothAdapter. I can't find a way to connect to the device. None of the existing solutions worked. Most of them are for creating a socket and communicating with it. I just want to connect to the device. Is it even possible? It's a bit frustrating to go to Settings -> Bluetooth -> Previous Devices -> Click on the device -> Connect or disconnect. Is there no method that gives us this functionality?

Edit: https://i.stack.imgur.com/iM9uF.jpg This is the feature I'm trying to implement. Instead of going all the way to the settings and clicking connect, I was trying to make a janky app to do it with one click.

cbhhargava
  • 23
  • 5
  • What do you mean by "connect", if you don't mean creating a socket, and you don't mean pairing? – LarsH Jun 21 '19 at 15:54
  • Connect in the sense my app doesn't communicate any information to the device. Just create an active connection. For example, I have 3 devices. Android watch, a headphones and speaker. I want to create a toggle so that I can connect and disconnect them. All the devices are already paired in advance and in range. Am I clear? Sorry for my English. It is not my first language. – cbhhargava Jun 21 '19 at 16:02
  • @LarsH I've added a screenshot of the feature that I'm trying to implement. – cbhhargava Jun 21 '19 at 16:15
  • In order to answer your question we first have to know what you're trying to do, which includes identifying the right terminology. It's confusing that the UI in your screenshot uses the word "connected" as in "previously connected devices." But it looks like those devices in your screenshot are ones that you **have previously paired with**, not devices you **are already paired** with, and I'm guessing that what you want to do is **pair** with them. I don't think there's much more you can do without creating a socket. – LarsH Jun 21 '19 at 17:54
  • If you can confirm that *pairing* is what you want to do, we can begin to try to help you. Edit the question title, or if you can't, let me know and I'll do it. – LarsH Jun 21 '19 at 17:57
  • The devices in the screenshot are already paired. That is the passkey is already accepted. I just want to connect to them. Consider this, there is my phone, my laptop and headphones. I'm currently listening music on headphones via laptop. I turned off the bluetooth on my laptop and now want to listen it using my phone. That is the feature I'm trying to implement. I have to do all those above steps in screenshot to connect a bt device which is already bonded to my android. So, does this help? If sockets are the answer, do they work with any device? Like headphones, bt mouse, watch etc.? – cbhhargava Jun 23 '19 at 12:30
  • Yes, I believe this description helps. I believe what you want to do is *pair with* a device that the phone *has previously paired with*, and is *still bonded with* (as you said), not a device the phone *is (still) paired with*. This page explains the process: https://developer.android.com/guide/topics/connectivity/bluetooth Beyond that, I don't know enough to help you. But see this answer: https://stackoverflow.com/a/32324097/423105 – LarsH Jun 24 '19 at 14:03
  • 1
    Yeah. I too came to the conclusion that there are no APIs that expose this behavior rn. Thanks for the help. – cbhhargava Jun 25 '19 at 15:49

0 Answers0