I'm scratching my head trying to find a way to detect bluetooth headset connect and disconnect events for Android 2.1. I see in API Level 11 that there are some explicit ones, but how do I do it in API level 7? I just want to know when the user connects or disconnects a headset or car stereo capable of playing audio, so that I can pause the sounds I'm playing.
4 Answers
There is no public APIs, This answer might help where the author used private APIs using reflections.
The author has also posted a comment on how he got it to work.

- 1
- 1

- 6,897
- 2
- 26
- 39
Not sure if this works in 2.1, but it works in 2.2 and 2.3.
It will capture Bluetooth-Headset connection state changes:
Declare the following intent-filter
<intent-filter >
<action android:name="android.bluetooth.headset.action.AUDIO_STATE_CHANGED" />
</intent-filter>
and in your Receiver in onReceive check for:
if ("android.bluetooth.headset.action.AUDIO_STATE_CHANGED".equals(intent.getAction())) {
headsetAudioState = intent.getIntExtra("android.bluetooth.headset.extra.AUDIO_STATE", -2);
}
and save the int as a static variable. Access it anytime you want to know if BT audio is connected(1) / disconnected(0). Not pretty, but gets the job done.
Also check out: https://github.com/android/platform_frameworks_base/blob/gingerbread/core/java/android/bluetooth/BluetoothHeadset.java

- 4,973
- 1
- 43
- 52
You have to setup a BroadcastReceiver
for android.bluetooth.headset.action.STATE_CHANGED
action. The Intent's extra android.bluetooth.headset.extra.STATE
contains current state (disconnected, connecting, connected). More info the Android source code

- 23,934
- 10
- 61
- 84

- 242
- 2
- 3