Android 系统应用程序的音频捕获权限

Audio capture permission for an Android system app

我能够使用 Android 播放捕获 API 创建一个系统应用程序来捕获 Android 10 系统中其他应用程序的音频。它无法捕获目标 SDK 为 28 的某些应用程序的声音(一旦我将这些应用程序升级到目标 SDK 29,它就会工作)。

这很令人费解,因为根据 Android official document and also this blog,默认情况下,系统应用程序应该能够捕获其他应用程序的声音,除非应用程序有意禁止(不是我的情况) .

好吧,链接文档中有一条注释(在这个 paragraph 中),它描述了这种行为

Note: The ability for an app's audio to be captured also depends on the app's targetSdkVersion.

By default, apps that target versions up to and including to Android 9.0 do not permit playback capture. To enable it, include android:allowAudioPlaybackCapture="true" in the app's manifest.xml file.

By default, apps that target Android 10 (API level 29) or higher allow their audio to be captured. To disable playback capture, include android:allowAudioPlaybackCapture="false" in the app's manifest.xml file.

感谢同事的帮助,我的应用程序在

之后运行
  1. 正在将系统应用升级为特权应用以获得CAPTURE_MEDIA_OUTPUT权限
  2. 设置私有字段mAllowPrivilegedPlaybackCapture 在 AudioMixingRule 对象中设置为“true”。

上面的 #2 是我在上次失败尝试中没有找到的关键。