Android 检测 AudioRecord/在不阻止其他应用程序的情况下录制音频的方法
现在,我的应用程序允许用户开始录制音频,并发出持续通知,可以使用 android.media.AudioRecord 在按下时暂停/重新开始录制。一切都很好,直到我意识到这会阻止任何其他应用程序使用 AudioRecorder(即谷歌语音搜索)。
有没有办法设置广播接收器来检测来自另一个应用程序对 AudioRecorder 的调用并暂停录音。或者,是否有另一种方式来录制不会干扰其他使用音频的应用程序的音频?
干杯!
Right now my application lets the user start recording audio and puts an ongoing notification that can pause/restart recording on press using android.media.AudioRecord. All was fine and dandy until I realized that this blocks any other App from using an AudioRecorder (ie google voice search).
Is there a way I can set up a broadcast reciever to detect a call for an AudioRecorder from another app and pause my recording. Alternatively, is there another way to record audio that wont interfere with other Apps that use audio?
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经研究这个问题有一段时间了。似乎没有干净的方法来实现这一点,因为没有广播在另一个应用程序想要访问麦克风时发出警报。
我们解决这个问题的方法(尽管不是很干净)是我们轮询前台的应用程序并获取其权限;如果该应用程序有权使用麦克风,我们将终止录制,直到前台没有具有麦克风权限的应用程序为止。
虽然轮询是一个解决方案,但如果有人有更好的解决方案,我将非常感兴趣!
I have been looking into this very question for a while now. It seems that there is no clean way of achieving this as there is no broadcast that alerts when another app would like access to the mic.
The way that we have solved it (albeit not cleanly) is we poll what app is in the foreground and get its permissions; if that app has permission to use the mic, we terminate recording until there isn't an app in the foreground with the mic permission.
Although polling is a solution, I would be very interested if anyone has better!