简体   繁体   中英

How take screenshot of entire screen programmatically in Android

With MediaRecorder API, you can easily take video capture of the entire screen (Including OS and other apps) https://developer.android.com/guide/topics/media/mediarecorder

But I want to capture images only when the user clicks on a button that appears always on top.

I know this is possible because I saw an app doing the exact same thing on playstore https://play.google.com/store/apps/details?id=com.mdiwebma.screenshot&hl=en&gl=US

And I pretty sure they are using something similar to MediaRecorder API because I tested their apps on a non rooted device

This is not a duplicate of How to programmatically take a screenshot on Android? because reponses suggested there either take capture of the app only or needs root access

I ended getting it to work.

MediaRecorder is for Video and Audio recording indeed. MediaProjection API is what I was looking from

Example in Kotlin: (almost what I was looking for)

https://gist.github.com/nosix/fcf1923f0c7cc42aa8c2ee70ff457b9c

Example in Java: (Near what I was looking for)

https://github.com/android/media-samples/tree/main/ScreenCapture

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM