Auto connect with already paired BT device - android

Goal:
I'm trying to connect my Android phone to an already paired bluetooth device when its in proximity.
Issue : I am novice to BT technology. I am pairing up my Android phone with a BT device using classic bluetooth API (SPP) as BT device is intent to send large data to mobile app.
The requirement/issue is : Mobile device should automatically connect with already paired BT device when in range. Note that we are using classic BT API and not the GATT.
How does the car audio system automatically connects with driver's phone. I think its the car's BT system who initiate pairing request with phone when car is turn on?

There are a lot of loose ends here. To reconnect to an already paired SPP device depends upon the behavior of the device. If it is passive (always in the slave role) you will have to actively connect to it. I have a passive SPP medical device and to auto reconnect to the device I have to 'continuously' do a discovery in the background (by continuously I mean to a discovery for 5 seconds every 10 seconds or something like that). When I detect the device I create an SPP socket and invoke the connect() method. The alternative is to have a UI that has the user invoke the connect() method when using the device. Hopefully the device is nice and becomes discoverable when it is ready to connect. If it is not discoverable then you need to (yuulk) poll it with connect attempts.
If you have an active device, you can set up a listener socket so the peer can connect to you and you avoid all that background discovery work. At least that is what I have had to deal with.

Yeah by periodic discovery of already paid BT device we can detect and auto pair with them but ar the cost of battery. This is what I had done.

Related

Android - Is there a way to share a Wi-Fi connection with a connected peripheral device over BLE seamlessly?

I know that there are ways to share internet via:
Creating a hot spot on the mobile phone
Bluetooth tethering?
NFC tags
However all these processes require some manual effort on the user side.
I am wondering if there is a way to seamlessly do this for the user the moment we pair with their peripheral device over BLE. Is there a way I can programmatically share the Wi-Fi connection the moment we are successfully connected?
Use Case:
I have a new speaker that can connect over BLE
I successfully pair my phone with the speaker over BLE
My speaker after pairing also automatically joins the same wifi network as my phone after

Android: I can't get bluetooth paired device

I can discover devices and createbond. It's working fine.
But when the user close the app and open again I'm already in bonded state and I only need open serial socket but I can't find the device!
GetBondedDevice gives all the device connected before and also the active one.
Because of that I can't understand is it realy connected and ready to open serialsocket!
Serial socket is not always active. I'm closing onDestroy or onPause to stop communicate.
To simplfy the question: I want to check if given mac address is paired and ready to open serial socket.
As you mentioned, paired devices and connected devices are two different things as follows:-
Paired devices: these are devices that have exchanged security keys and are therefore 'linked' to your Android device (this makes the reconnection easier). These can be either connected or unconnected.
Connected devices: these are devices that have an active channel with your Android device that can be used to exchange data.
In your case, to get devices that have an active connection to your device, you can use the getConnectedDevices or getConnectionState.
You can find more references here:-
How can I programmatically tell if a Bluetooth device is connected
Android: List connected Bluetooth devices
List connected Bluetooth devices

How to auto pair my BLE Peripheral on my device?

We are developing an application which needs the BLE Peripheral to be automatically paired with the smartphone when the smartphone is near the BLE Peripheral.
We are using RN4871 Microchip BLE Board,
First time when I pair the device from the settings, then power of the device and power on the device, it doesn't show in the Connected Device list, I mean Android doesn't automatically gets connected. Whereas this behavior is not seen in case of Bluetooth Headset.
What is the difference between a BLE Peripheral and Bluetooth Headset, how can i achieve this behavior
That a device is paired (or more correct, bonded) generally just means that the central and peripheral stores keys used for encryption etc. when they later connect.
FYI Peripherals can be programmed so that they advertise with a specific Bluetooth device address as target.
Back to your question. In Android, an "application" must initiate a connection to a device to make it connected (no matter if it's paired or not). That can either be a normal app you install or the built-in HID application in the Bluetooth stack. That said, the HID application will automatically connect to enabled bonded HID devices. So basically, if no application wants the peripheral connected, it won't stay connected.

Android Bluetooth Low Energy peripheral - Connection loss after bonding

I am implementing Bluetooth Low Energy's HID over GATT (HOGP) profile on Android Lollipop. My target is to use the phone as a keyboard/mouse, which can just plug and play with the default BLE (HID) drivers in Windows 8.1 laptop. The Android phone is supposed to act as BLE peripheral and the laptop should be in BLE central role.
Currently, I am able to establish a very short connection with the laptop. But just right after I enter the passkeys, and bonded successfully with the laptop, the BLE connection will be lost. Have anyone faced this kind of problems before? Or have any solutions on it?
Also, I failed to add generic access service to the gatt server in Android. I am curious if GAP service is included in Android BLE communication by nature? The reason I want to include this service is for defining the "device name", "appearance", and the "peripheral connection parameter update" characteristics. How I can do so?
Did you get your system fixed, I am seeing something kind of similar, where after bonding, my device will go to paired list, then about 20 sec later, the bluetooth on /off button will automatically switch to off position, wait 10 sec, then back
to on position, and my device is gone..

Reconnecting an Android app to a paired bluetooth device

I am developing an Android app that connects beautifully to a Bluetooth device. If that device is turned off, the BT connection is lost, understandably. I would like to reconnect with the device when it is turned back on or comes back in range. Is there an intent sent out by the system when it detects a paired BT device that I can catch with a broadcastreceiver or some other way?
I dont think there is an automatic way to do that.
However, you can have a service scanning periodically for devices and notifying your application when this specific device is found.

Categories

Resources