I want my app to take a screenshot of another screen every 5 minutes from a background service.I know ,MediaProjection API can achieve this,but every screenshot,it will pop up a window ,u need to click 'start immediately',that is not acceptable,i need take screenshot automatically,can someone give me some advice,thanks! i heard that AccessibilityService has the ability of takeScreenshot,someone can give me a demo demonstrating it,thanks! that is ths API
takeScreenshot Added in API level 30
public void takeScreenshot (int displayId, Executor executor, AccessibilityService.TakeScreenshotCallback callback) Takes a screenshot of the specified display and returns it via an AccessibilityService.ScreenshotResult. You can use Bitmap#wrapHardwareBuffer to construct the bitmap from the ScreenshotResult's payload.
Note: In order to take screenshot your service has to declare the capability to take screenshot by setting the R.styleable.AccessibilityService_canTakeScreenshot property in its meta-data. For details refer to SERVICE_META_DATA.
Parameters displayId int: The logic display id, must be Display#DEFAULT_DISPLAY for default display. executor Executor: Executor on which to run the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. callback AccessibilityService.TakeScreenshotCallback: The callback invoked when taking screenshot has succeeded or failed. See TakeScreenshotCallback for details. This value cannot be null.
I want my app to take a screenshot of another screen every 5 minutes from a background service.I know ,MediaProjection API can achieve this,but every screenshot,it will pop up a window ,u need to click 'start immediately',that is not acceptable,i need take screenshot automatically,can someone give me some advice,thanks! i heard that AccessibilityService has the ability of takeScreenshot,someone can give me a demo demonstrating it,thanks! that is ths API
takeScreenshot Added in API level 30
public void takeScreenshot (int displayId, Executor executor, AccessibilityService.TakeScreenshotCallback callback) Takes a screenshot of the specified display and returns it via an AccessibilityService.ScreenshotResult. You can use Bitmap#wrapHardwareBuffer to construct the bitmap from the ScreenshotResult's payload.
Note: In order to take screenshot your service has to declare the capability to take screenshot by setting the R.styleable.AccessibilityService_canTakeScreenshot property in its meta-data. For details refer to SERVICE_META_DATA.
Parameters displayId int: The logic display id, must be Display#DEFAULT_DISPLAY for default display. executor Executor: Executor on which to run the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. callback AccessibilityService.TakeScreenshotCallback: The callback invoked when taking screenshot has succeeded or failed. See TakeScreenshotCallback for details. This value cannot be null.