title: About Android 5.0 new APIs for screen capturing
body: <p>Android 5.0 introduced new APIs for screen capture. It also provides an (updated) <a href="https://android.googlesource.com/platform/development/+/lollipop-release/samples/ApiDemos/src/com/example/android/apis/media/projection/MediaProjectionDemo.java" rel="nofollow">sample</a> project on how to use it.</p>
  
  <p>I have two questions:</p>
  
  <ol>
  <li><p>I have run the sample project, it looks like the function which actually render the screen content to <code>SurfaceView</code> is <code>createVirtualDisplay()</code> which returns an <strong>instance</strong> of <code>VirtualDisplay</code>. How could I generate <strong>image</strong> file from this <code>VirtualDisplay</code> instance?</p></li>
  <li><p>Are these screen capture APIs can only be used to capture my app’s screen? Could it also be used to capture any screen even my app is not running in the foreground? According to the sample project, it always needs to ask for a user’s permission before capturing screen, and that permission dialog is popped up by calling <code>startActivityForResult(...)</code>. Looks like it can only capture my app’s screenshot. Anyone knows more about this? </p></li>
  </ol>