I'm trying to make a screenshot of an activity in android, I found many examples online, but none works properly. In my case with a broadcast-receiver I intercept a specific event, and I launch an activity and I need to make the screenshot of this activity? Does anyone have any advice?
PS. I have already imported all the permissions to be able to save the screens on the disk. I use android api 26.
code that I found online
try {
// image naming and path to include sd card appending name you choose for file
View view = getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b1 = rootView.getDrawingCache();
Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
//Find the screen dimensions to create bitmap in the same size.
int width = getWindowManager().getDefaultDisplay().getWidth();
int height = getWindowManager().getDefaultDisplay().getHeight();
Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
} catch (Throwable e) {
// Several error may come out with file handling or DOM
e.printStackTrace();
}
When the code reaches the line who try to create Bitmap b, return java null point exception, because b1 is null.