On my Android phone: How can I press and hold the standby key on the right side and the home button at the same time from my Delphi XE7 app. I.e. access these two buttons to make a screenshot from within my app (to the picture folder)?
-
1I'm not exactly sure what you mean, but if I understand correctly, you want to make your app virtually press a combination of buttons on the device to mimic a user taking a screenshot. This does not sound like the appropriate approach. Surely there's a more straight-forward way of taking a screenshot without even thinking about buttons. – Jerry Dodge Nov 03 '14 at 20:30
-
1http://stackoverflow.com/q/2661536 – Ken White Nov 03 '14 at 21:21
-
Agreed with @JerryDodge... Maybe instead of going about accessing hardware buttons ( which may be different across devices ) instead think of it from this angle: how can I screenshot what is currently in view in my application? Google appropriately and show what has and what hasn't worked for you and edit your question... As your question stands, you'll probably not get a lot of help from current effort shown. – ThisGuy Nov 03 '14 at 22:40
-
http://www.fmxexpress.com/create-device-scaled-screenshots-in-delphi-xe5-firemonkey-on-android-and-ios/ – ThisGuy Nov 03 '14 at 22:43
1 Answers
In API level 17 (Jelly Bean MR1) and higher, Android's com.android.uiautomator.core.UiDevice
class has two takeScreenshot()
methods:
public boolean takeScreenshot (File storePath)
Take a screenshot of current window and store it as PNG Default scale of 1.0f (original size) and 90% quality is used The screenshot is adjusted per screen rotation
Parameters
storePath
where the PNG should be written toReturns
true if screen shot is created successfully, false otherwise
public boolean takeScreenshot (File storePath, float scale, int quality)
Take a screenshot of current window and store it as PNG The screenshot is adjusted per screen rotation
Parameters
storePath
where the PNG should be written toscale
scale the screenshot down if needed; 1.0f for original sizequality
quality of the PNG compression; range: 0-100Returns
true if screen shot is created successfully, false otherwise
For older Android versions, there is no screenshot API, and you cannot simulate hardware key presses to force it programmably. Though it appears that there are ways to have View
objects render themselves to Bitmap
objects, which you can then use as needed.
There are third-party apps in the App Store that can take screenshots, so maybe you can invoke one of them using an Intent
.
And there are third-party screenshot libraries available, such as the Android Screenshot Library on Google Code:
Android Screenshot Library (ASL) enables to programmatically capture screenshots from Android devices without requirement of having root access privileges. Instead, ASL utilizes a native service running in the background, started via the Android Debug Bridge (ADB) once per device boot.

- 555,201
- 31
- 458
- 770