Atul Dhanuka
Atul Dhanuka

Reputation: 1463

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

Upvotes: 0

Views: 34

Answers (1)

Jay Panchal
Jay Panchal

Reputation: 302

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

Upvotes: 0

Related Questions