简体   繁体   中英

Android Screenshot from my Delphi XE7 app

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. Ie access these two buttons to make a screenshot from within my app (to the picture folder)?

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 to

Returns
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 to

scale
scale the screenshot down if needed; 1.0f for original size

quality
quality of the PNG compression; range: 0-100

Returns
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.

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