本文介绍了如何目前捕捉一切在屏幕上,包括对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过每一个可能SO文章concering捕捉屏幕(屏幕截图,screendump)编程方式在Android上,他们通常都具有相同的回答结束了。

I have looked at probably every SO article concering capturing the screen (screenshot, screendump) programmatically on Android, and they usually all end up with the same answer.

与它的问题是,它抓住了你指定的视图,但它并不捕捉任何可能之上的根视图的对话框。这是code口使用,即不能上头捕获任何

The problem with it is that it captures the View that you have specified, but it does NOT capture any Dialogs that may be "on top of" the "root view". This is the code I use, that fails to capture anything "on top":

Bitmap bitmap;
View v1 = findViewById(android.R.id.content);
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "myDump.jpg");

FileOutputStream outputStream;

try
{
    outputStream = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 10, outputStream);
    outputStream.flush();
    outputStream.close();
}

catch (Exception e)
{
  e.printStackTrace();
}

现在的问题是: 我怎么可以捕捉整个屏幕,包括那些在上面对话框的我只捕获了我写的应用程序,而不关心在主屏幕或类似的东西,只是东西都在我的根视图的顶部。

The question is: how can I capture the entire screen, including Dialogs that are on top? I am only interested in capturing the app that I am writing, not the home screen or anything like that, just anything that is on top of my root view.

我看过一些关于生根,但我真的希望,走的是应用我写的完整screendump不能是不可能的。

I did read something about rooting, but I really hope that taking a complete screendump of the app Im writing cannot be impossible.

推荐答案

这是可能的,你需要绘制所有视图根位图。试试这个库:它可以捕捉Dailogs到你的屏幕截图

It is possible, you need to draw all view roots to the bitmap. Try out this library: https://github.com/jraska/Falcon it can capture Dailogs to your screenshot.

这篇关于如何目前捕捉一切在屏幕上,包括对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:15