How to check whether microphone is used by any background app

前端 未结 3 845
情书的邮戳
情书的邮戳 2020-12-01 10:06

I have been searching for couple of days now and havent been able to find a suitable solution.

I am trying to check if any app in the background is using the microph

相关标签:
3条回答
  • 2020-12-01 10:29

    After searching more i found the solution and i am adding it here for anyone that needs it to find it easier.

    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;
    }
    
    0 讨论(0)
  • 2020-12-01 10:31

    I know this may sound a bit tedious or the long way... But have you considered recording a logcat? Record a log for both Kernel and apps. Recreate the issue, then compare both logs to see what program is occupied when the kernel utilizes the mic.

    0 讨论(0)
  • 2020-12-01 10:49

    You can do it the other way around.

    Get the microphone in your app.

    Get a list of the installed apps, who have a RECORD permission.

    Then check if one of these apps is on the foreground and if there is one release the microphone so that the other app can use it (for example when a phone call occurs).

    A bit dirty practice but I think it is what you are looking for.

    Cheers!

    0 讨论(0)
提交回复
热议问题