I need to know which event is triggered when connecting a microphone or a headset to your device, and I am using speech recognition and have observed that does not follow the same flow as when nothing is connected to the device.
I would like to know if there is some kind of solution because the application I'm creating at the moment is tested in a Smartphone, but in the future will require connecting a microphone or a headset.
A greeting and I hope your answers
PS: At the moment in the code I have nothing on external microphone or headset, but at the moment everything is running according to device microphone and speaker.
EDIT
I see the way of knowing whether the headset is connected is as follows:
private class MusicIntentReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
Log.d(TAG, "Headset is unplugged");
break;
case 1:
Log.d(TAG, "Headset is plugged");
break;
default:
Log.d(TAG, "I have no idea what the headset state is");
}
}
}
}
But how to redirect the audio input to the microphone of the headset? and the audio output to the headphone output?