title: Android Capture Screen to Surface of ImageReader
body: <p>I am currently learning code of one github project ScreenCapture, which can capture the screen and show the image in a surfaceview, here is the project <a href="https://github.com/Charlesjean/android-ScreenCapture" rel="nofollow">https://github.com/Charlesjean/android-ScreenCapture</a>. I tried to replace the surface of SurfaceView with surface of a ImageReader Object with the code below:<br></p>
  
  <pre><code> mImgReader = ImageReader.newInstance(mWidth, mHeight, ImageFormat.JPEG, 5);
      mSurface = mImgReader.getSurface();// mSurfaceView.getHolder().getSurface();
      mImgReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
          @Override
          public void onImageAvailable(ImageReader reader) {
              Log.i(TAG, "in OnImageAvailable");
  
          }
      }, mHandler);
  </code></pre>
  
  <p>and create VirtualDisplay like this:<br></p>
  
  <pre><code>mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
                mWidth, mHeight, mScreenDensity,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY |
                        DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
                mSurface, new VirtualDisplay.Callback() {
                    @Override
                    public void onResumed() {
                        Log.i(TAG, "onResumed");
                        super.onResumed();
                    }
  
                    @Override
                    public void onPaused() {
                        Log.i(TAG, "onPaused");
                        super.onPaused();
                    }
                }, mHandler);
  </code></pre>
  
  <p>but the <code>onImageAvailable</code> method is never called, does anyone have any experience on this? I could not figure out why this does not work.</p>