title: Android: How can you get framebuffer (screenshot) on rooted device?
body: <p>I tried :</p>
  
  <pre><code>process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0 &gt; /sdcard/frame.raw");
  process.waitFor();
  </code></pre>
  
  <p>but it doesn't work. My device is rooted.</p>
  
  <p>I see many answers that it requires rooted access, but no actual code to get the framebuffer.</p>
  
  <p>I also tried glReadPixels() but no luck.</p>
  
  <pre><code>public void TakeScreen() {
  
          DisplayMetrics dm = new DisplayMetrics();
          getWindowManager().getDefaultDisplay().getMetrics(dm);
          int width = dm.widthPixels;
          int height = dm.heightPixels;
  
          int screenshotSize = width * height;
          ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4);
          bb.order(ByteOrder.nativeOrder());
          gl.glReadPixels(0, 0, width, height, GL10.GL_RGBA,
                  GL10.GL_UNSIGNED_BYTE, bb);
          int pixelsBuffer[] = new int[screenshotSize];
          bb.asIntBuffer().get(pixelsBuffer);
          bb = null;
          Bitmap bitmap = Bitmap.createBitmap(width, height,
                  Bitmap.Config.RGB_565);
          bitmap.setPixels(pixelsBuffer, screenshotSize - width, -width, 0, 0,
                  width, height);
          pixelsBuffer = null;
  
          short sBuffer[] = new short[screenshotSize];
          ShortBuffer sb = ShortBuffer.wrap(sBuffer);
          bitmap.copyPixelsToBuffer(sb);
  
          for (int i = 0; i &lt; screenshotSize; ++i) {
              short v = sBuffer[i];
              sBuffer[i] = (short) (((v &amp; 0x1f) &lt;&lt; 11) | (v &amp; 0x7e0) | ((v &amp; 0xf800) &gt;&gt; 11));
          }
          sb.rewind();
          bitmap.copyPixelsFromBuffer(sb);
          saveBitmap(bitmap, "/screenshots", "capturedImage");
      }
  </code></pre>