How To Programmatically Take Screenshots With Android’s PixelCopy API

Take automated screenshots of your Android views with ease

Yanneck Reiß
Tech Takeaways

--

Photo by Aris Ioakimidis from Pexels

Taking screenshots on your smartphone is a common and easy task that on most devices can get accomplished with a fancy hardware-button combination or even with touch gestures on the screen.

Taking automated screenshots programmatically on the other hand may is not that obvious at a first glance.

Luckily Google provides us with the PixelCopy API that helps us with this task.

In this article, we take a look at the API and how we can use it to convert the currently visible content of your app into a Bitmap that afterward can be used for further processing.

PixelCopy API

The PixelCopy API provides a reliable method for converting a part of the currently visible Surface into a Bitmap.

Counterintuitive, the API doesn't use a direct copy function but requires to use itsrequest function.

--

--

Yanneck Reiß
Tech Takeaways

Follow me on my journey as a professional mobile and fullstack developer