2

I am developing an Android application for a VoIP call and have following issue:

If any other app like Hangouts or Skype is already having a call active, then the mic/recording control stays with it , even if I have called requestAudioFocus API of AudioManager from my application. Playback control comes to my application , but recording control stays with earlier apps.

Is there a way in Android to request the recording focus as well ?

Sameer Joshi
  • 329
  • 3
  • 16

1 Answers1

1

Just like Camera access, only one app at a time can access microphone. All that you can take care of in this scenario is just request microphone and if you don't get it, notify user related with the issue - 'Microphone is used by other application or Microphone is busy'

You can check mic availablity using following code -

private boolean validateMicAvailability(){
    Boolean available = true;
    AudioRecord recorder =
            new AudioRecord(MediaRecorder.AudioSource.MIC, 44100,
                    AudioFormat.CHANNEL_IN_MONO,
                    AudioFormat.ENCODING_DEFAULT, 44100);
    try{
        if(recorder.getRecordingState() != AudioRecord.RECORDSTATE_STOPPED ){
            available = false;

        }

        recorder.startRecording();
        if(recorder.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING){
            recorder.stop();
            available = false;

        }
        recorder.stop();
    } finally{
        recorder.release();
        recorder = null;
    }

    return available;
}

You can check indetail post here

Neji
  • 6,591
  • 5
  • 43
  • 66