智能客服
你问我答,随时在线为你解决问题
在错误日志中发现关键信息Failed to pick. Code: {"code":801},在API参考通用错误码,801错误码含义为:该设备不支持此API。
开发者在手机端使用screenshot.pick进行屏幕截图,该方法仅可在2in1设备上使用,因此手机端调用报错。
应避免在手机设备上使用此API进行截图,推荐使用组件截图或窗口截图,如下示例代码使用窗口截图方法,支持在手机元服务中运行:
import { image } from '@kit.ImageKit'; import { window } from '@kit.ArkUI'; import { BusinessError } from '@ohos.base'; @Entry @Component struct Index { @State pixmap?: image.PixelMap = undefined; build() { Navigation() { Row() { Image(this.pixmap) .width('80%') .height('80%') .border({ color: Color.Black, width: 2 }) .margin(5); }; Row() { Button('窗口截图') .onClick(() => { let context: Context = this.getUIContext().getHostContext() as Context; window.getLastWindow(context, (err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); return; } data.snapshot().then((pixelMap: image.PixelMap) => { this.pixmap = pixelMap; }).catch((err: BusinessError) => { console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); }); }); }); }; } .title('屏幕截图') .height('100%') .width('100%'); } }