title: How to run foreground service with open Camera from another foreground service in Android 11?
body: <p>I am testing now open camera in <code>foreground service</code> in Android 11 and I have problem with new Android 11 restrictions: <a href="https://developer.android.com/guide/components/foreground-services" rel="nofollow noreferrer">https://developer.android.com/guide/components/foreground-services</a></p>
  <p>Pseudo code:</p>
  <pre><code>//Service1 is started by JobScheduler.
  class Service1 extends Service {
      ...
      startForeground(ID_OF_SERVICE1_NOTIFICATION, getService1Notification())
      ...
      //Run another foreground service with open camera
      Intent i = new Intent(getApplicationContext(), Service2.class)
      ContextCompat.startForegroundService(context, i)
      ...
  }
  
  class Service2 extends Service {
      ...
      startForeground(ID_OF_SERVICE2_NOTIFICATION, getService2Notification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST);
      openCamera() // &lt;-- Policy exception
      ...
  }
  </code></pre>
  <p>Class Service1 is started by <code>JobScheduler</code> with <code>startForeground()</code> and show notification to user. Service1 can start (<code>ContextCompat.startForegroundService()</code>) Service2 with <code>startForeground()</code> and show notification to user too. Service2 opens camera. The user sees notification all the time.</p>
  <p>manifest edited:</p>
  <pre><code>&lt;service android:name=&quot;.service.Service2&quot;
      android:foregroundServiceType=&quot;camera|microphone&quot;
      android:stopWithTask=&quot;false&quot;/&gt; 
  </code></pre>
  <p>Edited <code>starForeground()</code> in <code>Service2</code> with flag <code>FOREGROUND_SERVICE_TYPE_MANIFEST</code>: (a special value indicates to use all types set in manifest file)</p>
  <p>The result from <code>Logcat</code>:</p>
  <blockquote>
  <p>Foreground service started from background can not have location/camera/microphone access: service com.example.test/.service.Service2</p>
  </blockquote>
  <p>Tried also <code>FOREGROUND_SERVICE_TYPE_CAMERA|FOREGROUND_SERVICE_TYPE_MICROPHONE</code>.</p>
  <p>I would like to keep the automation in starting the camera for user.
  Is there any way?</p>