6

I take screenshots within my app using:

private Bitmap takeScreenshot() {
    View rootView = findViewById(android.R.id.content).getRootView();
    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();
}

This works fine except that the result does not contain any shadow. How can I capture the shadows of elevated objects as well?

I think I can also make a fake shadow using a very old approach, but then this will be a very old approach and will neglect the concept of elevations and natural shadows. Which is I don't want.

Please reply.

Thanks.

Usman
  • 2,331
  • 2
  • 21
  • 29
  • Not sure if it fits your case, but API > 21 has `MediaProjection` which allows taking screenshots / recording video. https://github.com/googlesamples/android-ScreenCapture – InTwoMinds Jan 14 '16 at 20:44
  • Thank you, this is useful but not for my case. I want to save a screenshot for attachment purposes when the user clicks the share button in my app. So I wouldn't want my user to give a confirmation every time. – Usman Jan 15 '16 at 06:19

1 Answers1

0

I've used UiDevice.takeScreenshot(File) from UIAutomator.

You can try to implement it's way. It uses UiAutomation that available only since API 18.

Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60
  • Is it used to take screenshots using the computer? I want to take screenshots and present to the user at execution time. – Usman Feb 20 '16 at 15:52
  • No, it takes screenshot by the device itself. – Artem Mostyaev Feb 20 '16 at 19:50
  • Can you please guide me more? I tried to search it but I can't figure out exactly what should I do. I have tried UiAutomation.takeScreenshot(); but it gives error: "takeScreenshot" cannot be referenced from a static context – Usman Feb 22 '16 at 16:34
  • Sorry, I was wrong. It looks like that UiAutomation can only be used in unit-tests, I've used it there. I also have some feelings that it can be used in normal applications with `instrumentation` tag in manifest and then `Instrumentation.getUiAutomation` but this doesn't looks good. Sorry :( – Artem Mostyaev Feb 23 '16 at 07:54