I am trying to pair an android app with a bluetooth device, I need to know which event is to be called when the connection with this bluetooth device is lost.
You can use BroadCast receiver and capture the ACTION_ACL_DISCONNECTED event.
See here for more details:
How to programmatically tell if a Bluetooth device is connected? (Android 2.2)
Related
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.
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.
I have an android phone which is paired via bluetooth with a bluetooth headset device that I am programming for
To debug the headset code the smartphone with which the headset is paired should be receiving a call
Is it possible to simulate an incoming call to the android smartphone so that I do not have to make a real call to it? I do not need to write any code for the phone itself I just need it to be receiving a call so that the bluetooth headset thinks it is connected via HFP with the phone. If it is possible to use an audio file on the computer to simulate the audio in the call it would be even better.
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.
Function
BluetoothAdapter.getDefaultAdapter().getBondedDevices()
returns a list of available connected bluetooth devices
Can I get a notification if one of those devices suddenly becomes disconnected?
First of all getBondedDevices() returns not connected devices. These devices are paired or bonded and that's all. Connection establishes by socket.connect().
The second thing. You can register a broadcast receiver for all events such bond state changed or device is connected \ disconnected.
See more information here