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());
}
}