如何检查麦克风是否被任何后台应用程序使用 [英] How to check whether microphone is used by any background app

查看:266
本文介绍了如何检查麦克风是否被任何后台应用程序使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了几天,还没有找到合适的解决方案.

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 microphone, so my app can use it, otherwise i want just to show message "Microphone in use by another app".

我尝试检查所有在后台的应用程序及其权限,但这不能解决我的问题,因为有可穿戴的包package.app要求获得权限,但不会影响音频,或者没有使用它.

I tried checking all the applications in the background and their permissions but that doesnt solve my problem, since there is package wearable.app which asks for the permissions but it doesnt affect the audio, or it is not using it.

我尝试了可以​​在这里或在google上找到的其他解决方案,但似乎都不是正确的方法.

I tried the other solutions that i was able to find here or on google, but none of that seems to be the proper way.

我想检查是否未使用麦克风,以便我的应用程序可以使用它.

All i want to check if the microphone is not being used, so my app can use it.

任何建议,我都会感激.

Any suggestion i will appreciate.

推荐答案

在搜索了更多内容之后,我找到了解决方案,并在这里为需要它的人添加了解决方案.

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;
}

这篇关于如何检查麦克风是否被任何后台应用程序使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆