media_projection - Screen capture
The media_projection module provides screenshot functionality. Similar screenshot APIs in Pro 8 have been migrated to this module.
Requesting screen-capture permission launches an Activity. On Android 10+, the permission prompt can only be shown while the app is in foreground, and a foreground service must keep running during capture; otherwise new frames may not be delivered.
Table of contents
Classes
Enums
Interfaces
Functions
Functions
requestScreenCapture
requestScreenCapture(options?: ScreenCaptureOptions , context?: android.content.Context): Promise<ScreenCapturer>
Request screen-capture permission and resolve with a ScreenCapturer. If the user denies the permission or an error occurs, the promise rejects with ScreenCaptureRequestError.
Requesting screen-capture permission launches an Activity. On Android 10+, the permission prompt can only be shown while the app is in foreground, and a foreground service must keep running during capture; otherwise new frames may not be delivered.
Example
"nodejs";
const { requestScreenCapture } = require("media_projection");
async function main() {
const capturer = await requestScreenCapture();
const img = await capturer.nextImage();
console.log(img);
}
main();Parameters
options: Screen capture options.context: Optional ActivityContextused to request permission (rarely needed).
Returns
Promise<ScreenCapturer>
Resolves to a ScreenCapturer.
Throws
ScreenCaptureRequestError: Permission denied or request failed.
