简体   繁体   English

如何检查任何后台应用程序是否使用麦克风

[英]How to check whether microphone is used by any background app

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". 我正在尝试检查后台的任何应用程序是否正在使用麦克风,因此我的应用程序可以使用它,否则我只想显示消息“其他应用程序正在使用麦克风”。

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. 我尝试检查后台的所有应用程序及其权限,但这并没有解决我的问题,因为有wearable.app包请求权限,但它不影响音频,或者它没有使用它。

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

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. 获取已安装的应用程序列表,这些应用程序具有RECORD权限。

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! 干杯!

I know this may sound a bit tedious or the long way... But have you considered recording a logcat? 我知道这可能听起来有点乏味或漫长的道路......但你有没有考虑过录制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. 重新创建问题,然后比较两个日志以查看内核使用麦克风时占用的程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查应用程序是在前台还是后台 - How to check whether the app is in foreground or background Android - 如何检查麦克风当前正被某些其他应用程序使用 - Android - How to check Microphone is currently being used by some other application 如何通过 ADB 检查是否正在使用外部麦克风 - How to check if external microphone is being used via ADB 如何检查应用程序是在后台还是前台android。 使用以下代码但无法检查 - How to check whether a app is in background or foreground android. Using following code but unable check 如何检查是否使用耳机或内置麦克风进行麦克风输入? - How do I check if Headset or Internal Microphone is being used for microphone input? 如何检查代码是否在后台运行? - How to check whether code is running in background or not? 如何检查活动是在Android中的前景还是背景? - How to check whether activity is in foreground or background in android? 检查麦克风是否正在被其他应用程序使用? - Check Microphone is in use or not by other app? 检查用户之前是否使用过Facebook SDK来登录应用程序 - Check whether a user used facebook sdk to login into app previously 有没有办法检查Twitter应用程序是否在后台运行 - Is there any way to check if a twitter app is running in the background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM