This will not work when the application starts, but as intent filters are automatically registered, you can have a valid value after the application starts:
Announce the next intent filter
<intent-filter > <action android:name="android.bluetooth.headset.action.AUDIO_STATE_CHANGED" /> </intent-filter>
and in your receiver in onReceive check:
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 sound is connected (1) / muted (0). Not beautiful, but it does its job.
Also check: https://github.com/android/platform_frameworks_base/blob/gingerbread/core/java/android/bluetooth/BluetoothHeadset.java
source share