I am working on android voip application. I want to make sure if any other application is using mic. By this I want to prevent access to mic from other applications while I
Finally come to know that we can check mic availability as 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;
}
}