Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture everything currently on screen including Dialogs

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.

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.

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

like image 382
Ted Avatar asked Apr 18 '13 17:04

Ted


People also ask

How do you take a screenshot on a modal?

Press Command-Shift-4. Press the Space bar. Move the pointer over the desired interface element, which turns blue. Option-click to take the screenshot sans drop shadow.

How do I take screenshots?

Press the Power and Volume down buttons at the same time. If that doesn't work, press and hold the Power button for a few seconds. Then tap Screenshot.


1 Answers

use this library .... it works great for me. https://github.com/jraska/Falcon

  // Saving screenshot to file
            Falcon.takeScreenshot(this, imageFile);
            // Take bitmap and do whatever you want
            Bitmap bitmap = Falcon.takeScreenshotBitmap(this);
like image 187
MezzDroid Avatar answered Sep 27 '22 21:09

MezzDroid