androidaccessibilityService是否可以在低于30的api上进行屏幕截图?

pik*_*111 5 api android accessibilityservice android-studio

我正在使用 Android AccessibilityService 使用在 api 级别 30 上添加的某些方法来截取屏幕截图,我想知道它是否适用于低于 30 的 api

这是我重写的方法


    @Override
    public void takeScreenshot(int displayId, @NonNull Executor executor, @NonNull TakeScreenshotCallback callback) {
        super.takeScreenshot(displayId, executor, callback);
    }
Run Code Online (Sandbox Code Playgroud)

这就是我调用 takeScreenshot 方法的地方,它通过 takeScreenshot CallBack 给我结果


takeScreenshot(Display.DEFAULT_DISPLAY,
                getApplicationContext().getMainExecutor(), new TakeScreenshotCallback() {
            @RequiresApi(api = Build.VERSION_CODES.R)
            @Override
            public void onSuccess(@NonNull ScreenshotResult screenshotResult) {

                Log.i("ScreenShotResult","onSuccess");
                Bitmap bitmap = Bitmap.wrapHardwareBuffer(screenshotResult.getHardwareBuffer(),screenshotResult.getColorSpace());
                AccessibilityUtils.saveImage(bitmap,getApplicationContext(),"WhatsappIntegration");

            }

            @Override
            public void onFailure(int i) {

                Log.i("ScreenShotResult","onFailure code is "+ i);

            }
        });

Run Code Online (Sandbox Code Playgroud)

Zub*_*man 1

不幸的是,没有。我尝试在低于 31 的 API 上使用它并收到以下错误。

在此输入图像描述

这是我的 XML:

<accessibility-service
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackAllMask"
    android:notificationTimeout="100"
    android:canRetrieveWindowContent="true"
    android:canTakeScreenshot="true"/>
Run Code Online (Sandbox Code Playgroud)