12

I have already discovered the other device and I have already paired it. At least I have it in the list of paired devices on my Android phone.

Now on BluetoothSocket.connect() two problems can occur:

  1. The remote device is switched off or otherwise unavailable

  2. The remote device forgot about the pairing because it can only pair one other device and has been paired with a different phone

    => Then connect fails after a certain timeout.

Is it possible to check that an already paired device is really available and remembers that it was paired with my phone without connecting to it? This is not about detecting if a device is connected. Paired and visible is not the same as connected.

Community
  • 1
  • 1
Dirk Jäckel
  • 2,979
  • 3
  • 29
  • 47
  • Did you check this following links: http://stackoverflow.com/questions/14228289/android-device-bluetooth-pairing http://stackoverflow.com/questions/6675208/to-discover-and-pair-bluetooth-devices maybe you can get some ideas here. – She Smile GM Feb 12 '13 at 03:50

3 Answers3

4

I'm sorr t report but there's no way for your device to know another is in range except by attempting to connect to it. And, to know if the remote device has removed the pairing one would have to ask it, e.g. connect and see if it asks for pairing then.

Other ways would be get the user to confirm these before connecting, or maybe use an external channel TCP/IP or WiFi or NFC. If none of those then magical powers would be the only alternative. :-,)

alanjmcf
  • 3,430
  • 1
  • 17
  • 14
1
  1. Remembering the device that was connected is actually kinda simple. Once you have a successful bind to a device you get BluetoothDevice object. you can inquire it's unique mac address with getAddress(). Once you have the address save it to a shared preference. this covers the "was it paired" - the next time we use the BluetoothAdapter and receive the list of bound devices we can search for the saved device address among them.
  2. Now that we know the exact address of the device, how can we tell if it's "really available" ? Well, if it's enough for you to try and discover the device (startDiscovery ()) to check if it's available in the "discover" level - then you know the trick (list item 1). If you found out the device is discoverable and you need to test the device for full connectivity you'll have to open a new socket and see if it goes smooth.

In my experience I treat 3 different possible BT device situations:

  1. Device not bound
  2. Device bound - but not connected
  3. Device bound - and connected
Sean
  • 5,176
  • 2
  • 34
  • 50
0

You can get an already paired device list and cross verify them with current discoverable devices.So this will give you already paired devices those are in discoverable mode.

But for undiscoverable devices compulsory you have to connect with them. Try to create socket connection between them if data successfully sent remote device is active.

Also you can use getBondState () of remote device to check bonded state and register ACTION_BOND_STATE_CHANGED receiver for getting callback of bonded state changes.

Swapnil Deshmukh
  • 665
  • 1
  • 6
  • 23