Reconnecting an Android app to a paired bluetooth device - android

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.

Related

Not able to disconnect when manual press if i turn of and on the bluetooth

I am facing a problem while disconnecting a ble device.
I have an android application that talks to ble device, I connect to the GATT with the auto connect enabled, Now I have a button on which I am disconnecting the device and then closing GATT.
The disconnect is working fine when I normally go into the application, turn on my Bluetooth and then connect to the device.
But once the device is connected if I turn my phones Bluetooth of and then turn it on(I am calling a broadcast receiver when Bluetooth turned on or of), i am reconnecting to the previous device is auto-connect on. But this time if I try to disconnect it, does not disconnect the device.

Auto connect with already paired BT device

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.

Android - detect if device connected with another hardware?

I've received a requirement for detect whether my android device is connected with any other hardware like (Audio, car etc) and notify user if disconnected with that hardware.
I really don't know if these hardware connects with device either using Bluetooth or Local Wi-Fi? Can someone help please?
If the devices are connected via Bluetooth, register for the BluetoothDevice.ACTION_ACL_DISCONNECTED intent. It will fire whenever a Bluetooth device disconnects. Upon receiving this intent, examine its extras to find out which device disconnected:
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
For devices connected via WiFi, it depends on how the connection is established. If the device is a WiFi access point, register for connectivity change intents.
If Bluetooth state is not opened, just only onReceive() Local Wi-Fi connected hardware devices list change!
If Bluetooth state is opened,onReceive() Local Wi-Fi connected hardware devices list change and onReceive() already paired bluetooth devices list change.

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..

How to get connection status of Bluetooth device for Android

How to get the connection status of a bluetooth device for android i.e. "connected", "disconnected", "disconnecting" or "connecting" for the API level 7 onwards?
I am dying searching a lot on this issue but found nothing on regard of this. Neither am I able to disconnect a device which is not connected in my app because I don't know if it is connected or not.
I can know if a device is connected in my App using the Intent.ACTION_ACL_CONNECTED and Intent.ACL_DISCONNECTED , and I get the interrupt or alert when I get a device connected or disconnected.
Unfortunately, there is currently no way to detect whether a bluetooth device is connected. You can only detect connect/disconnect events.

Categories

Resources