如何阻止麦克风对其他应用使用? [英] How to block the mic for another app to use?

查看:730
本文介绍了如何阻止麦克风对其他应用使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在Android VoIP应用。我要确保,如果任何其他应用程序正在使用的麦克风。这个我想,当我用它来美元的其他应用程序话筒p $ pvent访问。

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 am using it.

请任何一个有想法,这将是对我很大的帮助。

Please any one has Idea, It will be very helpful to me.

谢谢,

推荐答案

终于知道,我们可以检查如下MIC可用性:

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

这篇关于如何阻止麦克风对其他应用使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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