BlackBerry - How to detect the bluetooth headset connection event? - blackberry

I have a bluetooth headset that I paired with my blackberry storm. Whenever I turn on/off the headset, my storm displays the message that the headset is been connected or disconnected and updates the bluetooth indicator icon. I would like to detect that headset connect change event in my application. How do i capture that event change? I know that "Audiolistener" can capture the headset connect event. but I don't know whether it will do for bluetooth headset.
thanks.

BlackBerry Support Community Forums:BlackBerry Development:Java Development:AudioListener:
There is no listener that provides notifications for when a user connects or disconnects a headset.
Mark Sohm
BlackBerry Development Advisor
www.BlackBerryDeveloper.com

Related

iOS Detect Bluetooth connection/disconnection

Is it possible to be notified when a Bluetooth Device is connected or disconnected from iOS even when my app is in background ?
On Android, I use the ACTION_ACL_CONNECTED and ACTION_ACL_DISCONNECTED events. But I cannot find equivalents for iOS.
I found the CBCentralManager that can be used to monitor Bluetooth events, but my functions aren't called when a bluetooth device is connected/disconnected, only when I enable/disable the bluetooth. Is it an error on my side or is it normal ?
I also found the doc about Audio Route changes, that can also be an idea to detect the bluetooth connections/disconnections. Just check the kind of new route and detect the connected bluetooth devices at that time.
In the doc, I also found NSNotification types like IOBluetoothHostControllerXXX but nothing is explained about them. Did someone already used them ?
Is there something better or am I missing something ?
You cannot receive notifications about the connection and disconnection of Bluetooth peripherals generally. You can get connection and disconnection events for BLE peripherals that your app connects to.
For example, if your app initiates a connection to a heart rate sensor then you will get a call to your CBCentralManagerDelegate connection function when the connection succeeds. If that device subsequently is switched off or goes out of range then you will get a call to the disconnection delegate method.
If some other app initiates and makes the connection then you will not get a callback.
As you mentioned, you can monitor audio route changes to infer that a Bluetooth audio device has been connected/disconnected, but this will also fire when headphones are plugged in.

iOS - is it possible to record from Bluetooth mic AND receive remote control events?

I'm developing an app that listens to voice commands and the way to start/stop listening to voice commands is via remote control (Airpods or wired headset). I tried various AVAudioSession options with AVAudioSessionCategoryRecord and AVAudioSessionCategoryPlayAndRecord and got the following result:
Whenever the default input is a bluetooth (Airpod) mic (AVAudioSessionCategoryOptionAllowBluetooth), the app doesn't receive remote control events. Whenever the default input is the built-in mic or a wired headset, the app does receive remote control events.
Does anyone know if it's possible to have both Bluetooth mic enabled and receive remote control events?
I tested on iOS 11.0.1 and 11.0.3.

Check Bluetooth off without Systemhint

I'm developing an app that connects to a peripheral by BLE.
How do I check bluetooth is off without an iOS system dialog?
Currently I listen to didUpdateState in the CBCentralManagerDelegate. But if bluetooth is powered off I get the event AND a system ui dialog telling me to activate bluetooth in settings.
Is there another way to check?
Make sure you are specifying false for the CBCentralManagerOptionShowPowerAlertKey when you instantiate your CBCentralManager object

How to record voice from a Bluetooth headset for iOS device?

I have an application that needs to record voice from Bluetooth headset. It needs work like Siri or Google Assistant. When I press button in App, it records voice from Bluetooth MIC rather than build in Mic. Is that possible?
My understanding is
1) either the Bluetooth is an Apple certificated External Accessory
2) or the Headset can implement a HFP like protocol to active a HFP link ?
Any hints?
If all you need is recording, it's quite straight if your bluetooth device is paired with iOS. All bluetooth headset with microphone will work well.
When you start to record, I think you have already changed your audio session category to play and record.
Then you can check all your available input route with
-[AVAudioSession availableInputs]
and iterate to find the bluetooth, then set it with
-[AVAudioSession setPreferredInput:error:]
Sometimes it will fail, you need to check the output parameter error to find if there is something wrong.

Handle iPhone calling from external device (e.g. a car)

How does a car's system handle calls from an iPhone? The device is plugged through into the car's system using the dock connector at the bottom of the iPhone. Now when a call comes through the car intercepts it and you can press a button (usually on the steering wheel) to answer and then speak through the inbuilt microphones of the car and listen through the speakers in the car. All of this is done through connecting the device into a dock.... how does this work?
P.S: Is it possible to initiate calls from an outside system as well?
P.P.S: All of this is done without an App being installed on the iPhone itself though...
Any bluetooth devices that implement HFP or HSP bluetooth profiles will be able to receive the call from iPhone.To display the info( Caller ID or Contact name) on the car kit, the device has to implement PBAP or MAP bluetooth profiles.No App is required on iPhone.

Resources