0

I faced problem with bluetooth SCO audio in my android app.

I registered a receiver for actions ACL_CONNECTED and ACL_DISCONNECTED to capture the bluetooth SCO device connection and disconnection. On receive of ACL_CONNECTED I am checking whether bluetooth device has Audio service (headset) or not, if has AUDIO service, I am instantiating AudioTrack (new AudioTrack(....)) and starting bluetooth SCO (startBluetoothSco(); setBluetoothScoOn(true);).

I have a button in my app to write pcm data to AudioTrack. In this app I am not able to hear sound of PCM data i written.

I tried without any receiver and in onCreate() only I instantiated AudioTrack and started bluetooth SCO. Before launching app, I connected headset to my device and tested, it is working fine.

But, why my app is not working when established bluetooth SCO connection at run-time depending on ACL_CONNECTED intent.

If anybody know the solution please reply me. I added all required permissions BLUETOOTH, BLUETOOTH_ADMIN, MODIFY_AUDIO_SETTINGS (don't report about spelling mistakes in these permissions).

Yugandhar Babu
  • 10,311
  • 9
  • 42
  • 67

1 Answers1

1

Using what version API?

When creating your receiver use BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED instead of ACL_CONNECTED.

intentFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); // API 11
intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED); // API 8
intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED); // API 14
swooby
  • 3,005
  • 2
  • 36
  • 43