I want to use methods of BluetoothHeadset class in Android 2.0+. Here is my code:
Class bluetoothHeadsetClass = Class.forName(\"android.bluetooth.Bluetoo
Also tried invoking this by reflection. Ultimately gave up and used a broadcastReceiver instead.
Declare the following 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