I haven't seen any callback oriented approaches to solving this, but there was a great solution posted in this SO question:
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;
}
Only way I could see this working is polling it on a background timed task thread. This post has a couple of answers on how to implement this and im sure you'll find plenty of other examples.
There may be a way to add a callback approach from openSL so that when the state is changed you can duck the music volume or whatever is desired, but it seems like people were struggling to implement this.