0

as title says, im trying to figure out how to programmatically take a screenshot in android without root or adb, what about executing script or simulating android keyevents? im trying to find solution but no success.

QuestionMark
  • 35
  • 1
  • 3

1 Answers1

4

On Android 5.0+, use the media projection APIs. They are somewhat under-documented. This sample project demonstrates how to take screenshots.

On Android 4.4 and lower, this is not possible, outside of perhaps some security flaws on specific device models.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • The `ScreenshotService` runs in background? – Faizan Mubasher May 21 '18 at 16:09
  • 1
    @FaizanMubasher: If you are referring to that sample app, it is a foreground service, mostly for user controls. There is nothing about the media projection APIs that requires a foreground service IIRC, but you are subject to the Android 8.0+ limitations on background services. – CommonsWare May 22 '18 at 00:58