How to take screenshot of a layout in android

倖福魔咒の 提交于 2019-12-01 20:41:18
KoalaKoalified

Have you got the

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Declared in your manifest?

Also if you want the entire view try this:

view1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view1.getDrawingCache());

Oh and this may save you some time:

private void openScreenshot(File imageFile) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(imageFile);
    intent.setDataAndType(uri, "image/*");
    startActivity(intent);
}

Src: How to programmatically take a screenshot in Android?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!