'CompileSDKtarget 30 taking the screenshot is not working
compileSdkVersion = 30
minSdkVersion = 24
targetSdkVersion = 30
till 29 it was working but from 30 my code stop working for taking screenshot
public static Bitmap getScreenShot(LinearLayout view) {
Bitmap bm = Bitmap.createBitmap(view.getChildAt(0).getWidth(),
view.getChildAt(0).getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bm);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return bm;
}
in return I m getting null value
Solution 1:[1]
try this..
public static Bitmap takescreenshot(View v) {
v.setDrawingCacheEnabled(true);
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
return b;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jay Panchal |
