Here's how I have configured Bluetooth connectivity in my Android app: Java Code for Bluetooth Connection:
Here is the code to connect device
private void connectToDevice() {
// Establish Bluetooth connection
try {
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
bluetoothSocket = targetDevice.createRfcommSocketToServiceRecord(uuid);
bluetoothSocket.connect();
inputStream = bluetoothSocket.getInputStream();
listenForData();
} catch (IOException e) {
e.printStackTrace();
}
}
Here with below code I am able to see my device
AudioDeviceInfo[] audioDevices = new AudioDeviceInfo[0];
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
audioDevices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
}
microphoneList = new ArrayList<>();
for (AudioDeviceInfo deviceInfo : audioDevices) {
int deviceType = deviceInfo.getType();
if (deviceType == AudioDeviceInfo.TYPE_BUILTIN_MIC ||
deviceType == AudioDeviceInfo.TYPE_BLUETOOTH_SCO ||
deviceType == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP) {
microphoneList.add(deviceInfo);
}
}
String[] microphoneNames = new String[microphoneList.size()];
for (int i = 0; i < microphoneList.size(); i++) {
microphoneNames[i] = microphoneList.get(i).getProductName().toString();
}
Here is the recording code
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int result = audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
// Proceed with starting Bluetooth SCO and recording
audioManager.setBluetoothScoOn(true);
btnRecordPressed(null);
}
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
VoskActivity.this.registerReceiver(mBluetoothScoReceiver, intentFilter);
private BroadcastReceiver mBluetoothScoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
// Start recording audio
Log.d("audio connected","");
} else if(state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED){
Log.d("audio disconnected","");
}
}
};
Expected Behavior
I expected that when I press the PTT button on my Inrico device, it would use its microphone to record my voice within the app.
Actual Behavior
However, it seems that the recording is using the phone's built-in microphone instead of the Inrico PTT device microphone.