How to lock a microphone for another application?

I am working on an android voip application. I want to make sure that any other application uses a microphone. In this regard, I want to prevent access to the microphone from other applications while I use it.

Please, someone has an idea, it will be very useful for me.

Thanks,

+4
source share
1 answer

Finally, we find out that we can check the availability of the microphone, as shown below:

private void validateMicAvailability() throws MicUnaccessibleException { AudioRecord recorder = new AudioRecord(AudioSource.MIC, 44100, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_DEFAULT, 44100); try{ if(recorder.getRecordingState() != AudioRecord.RECORDSTATE_STOPPED ){ throw new MicUnaccessibleException("Mic didn't successfully initialized"); } recorder.startRecording(); if(recorder.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING){ recorder.stop(); throw new MicUnaccessibleException("Mic is in use and can't be accessed"); } recorder.stop(); } finally{ recorder.release(); recorder = null; } } 
+1
source

Source: https://habr.com/ru/post/1479522/


All Articles