我需要将Activity内容保存到.pdf文件中。像截图一样的东西。我可以使用以下代码将活动的各个视图保存到文件中:
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(600,300, 1).create();
PdfDocument.Page page = document.startPage(pageInfo);
View content = findViewById(R.id.editText1);
content.draw(page.getCanvas());
document.finishPage(page);
但是如何保存(printscreen)整个活动,而不仅仅是一个视图?
谢谢。
答案 0 :(得分:0)
You can take a screenshot of the current activity using the given code
public void saveBitmap(Bitmap bitmap) {
File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
and make sure give write permissions of the storage in manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />