Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect that an already discovered and paired device is available? [duplicate]

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.

like image 634
Dirk Jäckel Avatar asked Nov 29 '12 12:11

Dirk Jäckel


People also ask

How do I see previously connected devices on Bluetooth?

Swipe down from the top of the screen. Touch and hold Bluetooth . If your accessory is listed under "Available media devices," next to your device's name, tap Settings . If no accessories are listed under "Previously connected devices," tap See all.

What does it mean when two devices are paired?

Pairing is the process required to mutually register the information on BLUETOOTH devices to be connected wirelessly.

How do I find paired devices on Android?

By using BluetoothAdapter method getBondedDevices(), we can get the Bluetooth paired devices list. Following is the code snippet to get all paired devices with name and MAC address of each device. // Get paired devices. // There are paired devices.

How do I find my Bluetooth device nearby?

To find an active Bluetooth device, first make sure you have Bluetooth enabled on your smartphone. Next, download Wunderfind for your iPhone or Android device and launch the app. Immediately, you'll see a list of Bluetooth devices that your smartphone has detected using its built-in Bluetooth radio.


2 Answers

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. :-,)

like image 96
alanjmcf Avatar answered Oct 24 '22 12:10

alanjmcf


  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
like image 30
Sean Avatar answered Oct 24 '22 14:10

Sean