1

I am trying to take screenshots of the Android device. I want to take the screenshot of other app using my app. That's why I have created a floating widget button. I put the screenshot taking method in widget button but the problem is when I am taking the screenshot it is only capturing the floating buttons view and not capturing other components of the screen (i.e. other apps or if an app is opened it is not capturing the opened app).

I am passing view of floating widget button CaptureButton.

CaptureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {



            Bitmap b = Screenshot.takeScreenshotOfRootView(v);

        }
    });

Screenshot.java file.

public class Screenshot {

public static Bitmap takeScreenshot(View view){
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache(true);
    Bitmap b =Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);
    return  b;


}


public static Bitmap takeScreenshotOfRootView(View v){

    return  takeScreenshot(v.getRootView());
}

}

Mitu Vinci
  • 455
  • 9
  • 21
  • 1
    https://stackoverflow.com/a/46394134/115145 – CommonsWare Jan 27 '19 at 21:41
  • @CommonsWare Thanks. From this link androidshooter project did work for me, though I had to customize it. :) – Mitu Vinci Jan 28 '19 at 18:22
  • @MituVinci can you share your code, I'm facing the same issue, I also have a floating widget and want to take screenshots where ever the user is on the phone. Can you help me out please – Tehleel Mir Apr 12 '21 at 06:15

0 Answers0