我们正在开发实时流媒体视频应用程序。
因此,我们需要为音频和视频内容提供安全保障。
我所尝试的
我能够通过以下代码帮助限制屏幕截图和视频内容:
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
但我无法限制其他应用程序通过音频录制。
如何限制其他应用程序的音频录制?
我们正在开发实时流媒体视频应用程序。
因此,我们需要为音频和视频内容提供安全保障。
我所尝试的
我能够通过以下代码帮助限制屏幕截图和视频内容:
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
但我无法限制其他应用程序通过音频录制。
如何限制其他应用程序的音频录制?
我从未听说过Android中有这样的官方工具,可以简化这个过程。
但是我认为你可以指示另一个应用程序记录音频。尝试在您的代码中使用MediaRecorder。例如,您将创建其实例,并将麦克风(MediaRecorder.AudioSource.MIC)作为输入源。作为指示器,其他应用程序正在使用麦克风时,您将捕获异常,当您开始录制(mRecorder.start())时。如果您没有捕获异常,则表示麦克风硬件可供使用。因此现在没有人正在录制音频。 这个想法是您应该每次应用程序进入前台时进行检查。例如,在onResume()或onStart()生命周期回调中。例如:
@Override
protected void onResume() {
super.onResume();
...
boolean isMicFree = true;
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setOutputFile("/dev/null");
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
...
// Configure MediaRecorder
...
try {
recorder.start();
} catch (IllegalStateException e) {
Log.e("MediaRecorder", "start() failed: MIC is busy");
// Show alert dialogs to user.
// Ask him to stop audio record in other app.
// Stay in pause with your streaming because MIC is busy.
isMicFree = false;
}
if (isMicFree) {
Log.e("MediaRecorder", "start() successful: MIC is free");
// MIC is free.
// You can resume your streaming.
}
...
// Do not forget to stop and release MediaRecorder for future usage
recorder.stop();
recorder.release();
}
// onWindowFocusChanged will be executed
// every time when user taps on notifications
// while your app is in foreground.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
// Here you should do the same check with MediaRecorder.
// And you can be sure that user does not
// start audio recording through notifications.
// Or user stops recording through notifications.
}
我想重申这只是一个想法。