title: Can a third-party accessibility service capture audio on Android 10?
body: <p>I want to build an accessibility service that can capture audio even when other applications are using the microphone (video camera, phone, voice recorder, Shazam, etc). Android 10 introduced audio sharing, but it's not clear whether third-party accessibility services can capture audio from other apps.</p>
  <p><a href="https://developer.android.com/guide/topics/media/sharing-audio-input" rel="nofollow noreferrer">https://developer.android.com/guide/topics/media/sharing-audio-input</a></p>
  <blockquote>
  <p>For the purpose of capturing audio, Android distinguishes two kinds of
  apps:</p>
  <ul>
  <li><strong>&quot;Ordinary&quot; apps are installed by the user.</strong></li>
  <li>&quot;Privileged&quot; apps come pre-installed on the device. These include the Google Assistant, and all accessibility services.</li>
  </ul>
  </blockquote>
  <p>A <strong>third-party accessibility service</strong> is installed by the user, therefore it's an <strong>ordinary app</strong>.</p>
  <blockquote>
  <p>The prioritization rules for using and sharing audio input are as follows:</p>
  <ul>
  <li>Privileged apps have higher priority than ordinary apps.</li>
  <li>Apps with visible foreground UIs have higher priority than background apps.</li>
  <li>Apps capturing audio from a privacy-sensitive source have higher priority than apps that are not.</li>
  <li><strong>Two ordinary apps can never capture audio at the same time.</strong> In some situations, a privileged app can share audio input with another app. If two background apps of same priority are capturing audio, the last one started has higher priority.</li>
  </ul>
  </blockquote>
  <p>A <strong>third-party accessibility service</strong> is an <strong>ordinary app</strong>, therefore it can't capture audio at the same time as another app.</p>
  <blockquote>
  <p><strong>Accessibility service + ordinary app</strong></p>
  <p>Android shares the input audio according to these rules:</p>
  <ul>
  <li><p><strong>If the service's UI is on top, both the service and the app receive audio input.</strong> This behavior offers functionality like controlling a voice call or video capture with voice commands.</p>
  </li>
  <li><p>If the service is not on top, this case is treated like the ordinary two-app case below.</p>
  </li>
  </ul>
  </blockquote>
  <p>This section introduces a distinction between an <strong>accessibility service</strong>, an <strong>ordinary app</strong>, and a <strong>privileged apps</strong>. Does that mean that a <strong>third-party accessibility service with its UI on top</strong> can receive audio from ordinary apps?</p>