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:
The remote device is switched off or otherwise unavailable
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.
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.
Pairing is the process required to mutually register the information on BLUETOOTH devices to be connected wirelessly.
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.
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.
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. :-,)
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. 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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With