openharmony 鸿蒙 js-apis-awareness-onScreen-sys

2026-08-25 浏览 (1)

@ohos.multimodalAwareness.onScreen (Onscreen Awareness) (System API)

This module provides the onscreen awareness capability.

NOTE

  1. The initial APIs of this module are supported since API version 20. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  2. The APIs provided by this module are system APIs.

Modules to Import

import { onScreen } from '@kit.MultimodalAwarenessKit';

Scenario

Enumerates the scenarios of the onscreen content.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameValueDescription
UNKNOWN0Unknown scenario.
ARTICLE1Article scenario.

EventType

Enumerates the control event types.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameValueDescription
SCROLL_TO_HOOK1Scrolling to the hook.

Paragraph

Defines the paragraph information.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
hookIdnumberNoYesHook ID of the paragraph, which is the identifier of each main paragraph.
chapterIdnumberNoYesChapter ID of the paragraph, which is the identifier of each subchapter.
titlestringNoYesTitle of the paragraph.
textstringNoYesContent of the paragraph.

ContentOptions

Defines the options for obtaining the onscreen content.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
windowIdnumberNoYesID of the window whose content needs to be obtained. If this parameter is not set or is set to undefined, the content of the full-screen window is obtained by default.
contentUnderstandbooleanNoYesWhether content understanding is required. The default value is False.
pageLinkbooleanNoYesWhether to obtain the page link. The default value is False.
textOnlybooleanNoYesWhether to obtain only the text and divide the text into paragraphs. The default value is False.

PageContent

Defines the onscreen content.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
windowIdnumberNoNoWindow ID of the onscreen content.
sessionIdnumberNoNoSession ID, which identifies the call action.
bundleNamestringNoNoBundle name of the onscreen content.
scenarioScenarioNoYesScenario of the onscreen content. This parameter is available only when options.contentUnderstand is set to True.
titlestringNoYesTitle of the onscreen content. This parameter is available only when options.contentUnderstand is set to True.
contentstringNoYesBody of the onscreen content. This parameter is available only when options.contentUnderstand is set to True.
pageLinkstringNoYesPage link of the onscreen content. This parameter is available only when options.pageLink is set to True.
paragraphsParagraph[]NoYesParagraph information of the onscreen content. This parameter is available only when options.textOnly is set to True.

ControlEvent

Defines a control event.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
windowIdnumberNoNoID of the window to be operated.
sessionIdnumberNoNoID of the session to be operated. The hook ID and the session ID can be obtained from PageContent of a session.
eventTypeEventTypeNoNoControl event type.
hookIdnumberNoYesHook ID corresponding to the control event. The hook ID and the session ID can be obtained from PageContent of a session.

OnscreenAwarenessCap23+

Defines onscreen awareness capabilities (including but not limited to awareness in a reading scenario and OCR).

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
capListstring[]NoYesCapability list, including the capabilities for obtaining page content, page link, and text selection information. The following table describes the specific capabilities.
groupIdstringNoYesService group ID. A group of capabilities preset based on service scenarios. Service scenarios can be subscribed to in a unified manner. The following table describes the specific group IDs.

Parameter restrictions:
You can use the on-screen awareness feature through capList or groupId.

  • Logical relationship: capList and groupId are mutually supplementary and mandatory. At least one of them must be provided and cannot be empty.

  • Verification rule: When the API is called, the system checks capList and groupId separately.

  • Capability list: Use the on-screen awareness feature by capList or groupId. The definitions are as follows.

    • Capabilities supported by capList
    CapabilityFunction
    ActicleObtains the information about awareness in a reading scenario.
    ShortVideoObtains the information about awareness in a short video scenario.
    TodoObtains the information about awareness in a to-do scenario.
    ActivityObtains the awareness information of basic services.
    UiImageObtains the information about sub-images on a page.
    JumpContextHighlights and jumps to a specified context.
    QuickSnapObtains the information about a single snapshot.
    Usage specifications: This capability is used only in the trigger API. It takes effect only when capList is set to QuickSnap. For other APIs, error code 401 is returned.
    • Capabilities supported by groupId
    CapabilitySub-capabilityFunction
    SmartEdgeActicleObtains the information about awareness in a reading scenario.
    SmartEdgeShortVideoObtains the information about awareness in a short video scenario.
    SmartEdgeTodoObtains the information about awareness in a to-do scenario.
    SmartEdgeActivityObtains the awareness information of basic services.

OnscreenAwarenessOptions23+

Defines the list of onscreen awareness parameters, which is used to obtain onscreen information in specific scenarios. For example, a window ID is provided to collect application UI content and links.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
parametersRecord<string, Object>NoYesList of awareness parameters. The parameter result is a key-value data object.

CollectStrategy23+

Defines a page information collection policy.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameValueDescription
ALLOW1 << 0Collection is supported.
SPLIT_SCREEN1 << 1Collection policy of the split-screen window on the application.
UNSUPPORTED_APP1 << 2Automatic collection is not supported.
PRIVATE_WINDOW1 << 3Privacy window of the application.
ANCO_APP1 << 4VM application, which is a non-HarmonyOS application.
ALLOW_USER_CHANGE1 << 5Collection policies can be configured.
BUSINESS_APP1 << 6Application data can be collected.
FLOAT_SCREEN1 << 7Floating window.
PIP_SCREEN1 << 8Picture-in-picture mode.
LAUNCHER1 << 9Desktop application.

AwarenessItem23+

Provides page information, which includes:

  • Basic page information, such as page content, links, and screenshots.
  • Page entity information, such as the title and body of a page article.
  • Page interaction information, such as clicks and scrolling.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
itemInfoRecord<string, Object>YesNoEntity information of the awareness result, including the content, links, screenshots, and other entity information.

EntityInfo23+

Provides entity information perceived, including content, links, images, and other types of entities.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
entityNamestringYesNoName of the perceived entity, which is fixed.
entityInfoRecord<string, Object>YesNoEntity information of the awareness result, including the content, links, images, and other entity information.

OnscreenAwarenessInfo23+

Returns the list of onscreen awareness information.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
resultCodenumberYesNoReturn code. The default value 0 indicates success.
timestampnumberYesNoTimestamp for accessing a specified page.
uidstringYesYesApplication UID.
bundleNamestringYesYesApplication bundle name.
appNamestringYesYesApplication name.
miniProgramIdstringYesYesApplet ID, for example, the ID of WeChat or Alipay.
miniProgramNamestringYesYesName of a third-party mini program.
appIndexnumberYesYesApplication index.
pageIdstringYesYesApplication page ID.
sampleIdstringYesYesCollection record ID.
collectStrategynumberYesYesPage collection policy, which is the bitwise OR operation combination of CollectStrategy.
displayIdnumberYesYesDisplay ID.
windowIdnumberYesYesWindow ID.
languageInfostringYesYesPage language information.
pageTagsstring[]YesYesPage tag information.
itemsAwarenessItem[]YesYesData item information.
entityInfoEntityInfo[]YesYesEntity information.

ReadingScreenPermissionStatus23+

Returns the status of the permission for reading screen information.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

NameTypeRead-OnlyOptionalDescription
readingStatenumberYesNoWhether screen reading is allowed.
0: no
1: yes
readingCodenumberYesYesIf the screen information cannot be read, the corresponding status code will be returned.

onScreen.getPageContent

getPageContent(options?: ContentOptions): Promise<PageContent>

Obtains the onscreen content when a window is displayed on the screen.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
optionsContentOptionsNoOptions for obtaining the onscreen screen content. By default, the window ID is not specified, and other options are False.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.
34000002The application or page is not supported.
34000003The window ID is invalid. Possible causes: 1. window id is not passed when screen is split. 2. passed window id is not on screen or floating.
34000004The page is not ready.
34000006The request timed out.

Example

import { onScreen } from '@kit.MultimodalAwarenessKit';
import { BusinessError } from '@kit.BasicServicesKit';

let options: onScreen.ContentOptions = {
   contentUnderstand: true,
   pageLink: true
};
try {
   onScreen.getPageContent(options).then((pageContent: onScreen.PageContent) => {
      console.info("get page content succeed, bundleName = " + pageContent.bundleName);
   }).catch((err: BusinessError) => {
      console.error("get page content failed, errCode = " + err.code);
   });
} catch (err) {
   console.error('get page content failed, errCode = ' + err.code);
}

onScreen.sendControlEvent

sendControlEvent(event: ControlEvent): Promise<void>

If the target window is displayed on the screen, you can use this API to send screen control events based on the paragraph information obtained via onScreen.getPageContent.

Required permissions: ohos.permission.SIMULATE_USER_INPUT.

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
eventControlEventYesOnscreen control event.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.SIMULATE_USER_INPUT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.
34000005The target is not found.

Example

import { onScreen } from '@kit.MultimodalAwarenessKit';
import { BusinessError } from '@kit.BasicServicesKit';

let options: onScreen.ContentOptions = {
   contentUnderstand: true,
   textOnly: true
};
let event: onScreen.ControlEvent|undefined = undefined;
try {
   onScreen.getPageContent(options).then((pageContent: onScreen.PageContent) => {
      if (pageContent.paragraphs != undefined && pageContent.paragraphs.length > 0 &&
         pageContent.paragraphs[0].hookId != undefined) {
         event = {
            windowId: pageContent.windowId,
            sessionId: pageContent.sessionId,
            hookId: pageContent.paragraphs[0].hookId,
            eventType: onScreen.EventType.SCROLL_TO_HOOK
         };
      }
   }).catch((err: BusinessError) => {
      console.error("get page content failed, errCode = " + err.code);
   });
} catch (err) {
   console.error('invoke failed, errCode = ' + err.code);
}
if (event != undefined) {
   try {
      onScreen.sendControlEvent(event).catch((err: BusinessError) => {
         console.error("send control event failed, errCode =" + err.code);
      })
   } catch (err) {
      console.error('invoke failed, errCode = ' + err.code);
   }
}

onScreen.subscribe23+

subscribe(capability: OnscreenAwarenessCap, callback: Callback<OnscreenAwarenessInfo[]>, options?: OnscreenAwarenessOptions): void

Enables proactive awareness on screen content and subscribes to a screen awareness result.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
capabilityOnscreenAwarenessCapYesOnscreen awareness capability list.
optionsOnscreenAwarenessOptionsNoOnscreen awareness parameter list.
callbackCallback<OnscreenAwarenessInfo[]>YesCallback function, which returns the onscreen awareness result. The returned onscreen awareness information list OnscreenAwarenessInfo[] contains a maximum of two awareness information items.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.
34000002The application or page is not supported.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
let onscreenAwarenessCap: onScreen.OnscreenAwarenessCap = {
   groupId: 'SmartEdge',
}

let onscreenAwarenessOptions: onScreen.OnscreenAwarenessOptions = {
   parameters: {
      "SmartEdge" : {
         "windowId":'102',
      }
   }
}
try {
   onScreen.subscribe(onscreenAwarenessCap, (info: onScreen.OnscreenAwarenessInfo[]) => {
      console.info(`subscribe resultCode: ${info[0].resultCode}`);
   }, onscreenAwarenessOptions);
} catch (err) {
   console.error('subscribe failed, errCode = ' + err.code);
}

onScreen.unsubscribe23+

unsubscribe(capability: OnscreenAwarenessCap, callback?: Callback<OnscreenAwarenessInfo[]>): void

Disables proactive awareness on screen content and unsubscribes from a screen awareness result.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

Parameters

NameTypeMandatoryDescription
capabilityOnscreenAwarenessCapYesOnscreen awareness capability list.
callbackCallback<OnscreenAwarenessInfo>NoCallback to unregister. If this parameter is not passed, all callbacks of the awareness capability are unregistered. The returned onscreen awareness information list OnscreenAwarenessInfo[] contains a maximum of two awareness information items.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
let onscreenAwarenessCap: onScreen.OnscreenAwarenessCap = {
   groupId: 'SmartEdge'
}

try {
  onScreen.unsubscribe(onscreenAwarenessCap, (info: onScreen.OnscreenAwarenessInfo[]) => {
    console.info(`unsubscribe resultCode: ${info[0].resultCode}`);
  });
} catch (err) {
  console.error('unsubscribe failed, errCode = ' + err.code);
}

onScreen.trigger23+

trigger(capability: OnscreenAwarenessCap, options?: OnscreenAwarenessOptions): Promise<OnscreenAwarenessInfo>

Proactively triggers screen content awareness and obtains the current screen awareness result.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

Parameters

NameTypeMandatoryDescription
capabilityOnscreenAwarenessCapYesOnscreen awareness capability list.
optionsOnscreenAwarenessOptionsNoOnscreen awareness parameter list.

Return value

TypeDescription
Promise<OnscreenAwarenessInfo>Promise used to return the onscreen awareness result.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.
34000002The application or page is not supported.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
let onscreenAwarenessCap: onScreen.OnscreenAwarenessCap = {
  capList: [
    'UiImage'
  ]
}

let onscreenAwarenessOptions: onScreen.OnscreenAwarenessOptions = {
  parameters: {
    "windowId": 102
  } as Record<string, Object>
}
try {
  let info: onScreen.OnscreenAwarenessInfo =
    await onScreen.trigger(onscreenAwarenessCap, onscreenAwarenessOptions);
  console.info(`trigger resultCode: ${info.resultCode}`);
} catch (err) {
  console.error('trigger failed, errCode = ' + err.code);
}

onScreen.capture23+

capture(capability: OnscreenAwarenessCap, options?: OnscreenAwarenessOptions): Promise<OnscreenAwarenessInfo[]>

Proactively triggers screen content awareness to obtain page information.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

Parameters

NameTypeMandatoryDescription
capabilityOnscreenAwarenessCapYesOnscreen awareness capability list. For details, see the following supported capability list.
optionsOnscreenAwarenessOptionsNoOnscreen awareness parameter list.

capList capabilities supported by the capture API

capList CapabilityFunction
UiImageObtains the information about sub-images on a page.
QuickSnapObtains screenshot information.

Return value

TypeDescription
Promise<OnscreenAwarenessInfo[]>Promise used to return the onscreen awareness result. The returned onscreen awareness information list OnscreenAwarenessInfo[] contains a maximum of two awareness information items.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.
34000002The application or page is not supported.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
let onscreenAwarenessCap: onScreen.OnscreenAwarenessCap = {
  capList: [
    'UiImage',
  ]
}
try {
  let info: onScreen.OnscreenAwarenessInfo[] = await onScreen.capture(onscreenAwarenessCap);
  console.error(`capture resultCode: ${info[0].resultCode}`);
} catch (err) {
  console.info(`capture failed, error: ${err}`);
}

onScreen.interact23+

interact(capability: OnscreenAwarenessCap, options?: OnscreenAwarenessOptions): Promise<OnscreenAwarenessInfo[]>

Proactively triggers screen behavior interaction to identify screen behaviors and return behavior receipts. For example, after a link is clicked, the system accurately jumps to the specified paragraph and highlights the text based on the receipt information.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

Parameters

NameTypeMandatoryDescription
capabilityOnscreenAwarenessCapYesOnscreen awareness capability list. For details, see the following supported capability list.
optionsOnscreenAwarenessOptionsNoOnscreen awareness parameter list.

capList capabilities supported by the interact API

capList CapabilityFunction
JumpContextHighlights and jumps to a specified context.

Return value

TypeDescription
Promise<OnscreenAwarenessInfo[]>Promise used to return the onscreen awareness result. The returned onscreen awareness information list OnscreenAwarenessInfo[] contains a maximum of two awareness information items.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.
34000002The application or page is not supported.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
let onscreenAwarenessCap: onScreen.OnscreenAwarenessCap = {
  capList: [
    'JumpContext',
  ]
}

let onscreenAwarenessOptions: onScreen.OnscreenAwarenessOptions = {
  parameters: {
    "JumpContext" : {
      "pageId":'156',
      "textCompIdList": ['235'],
      "text": 'Article beginning'
    }
  }
}

try {
  let info: onScreen.OnscreenAwarenessInfo[] = await onScreen.interact(onscreenAwarenessCap, onscreenAwarenessOptions);
  console.error(`interact resultCode: ${info[0].resultCode}`);
} catch (err) {
  console.info(`interact failed, error: ${err}`);
}

onScreen.apperceive23+

apperceive(capability: OnscreenAwarenessCap, options?: OnscreenAwarenessOptions): Promise<OnscreenAwarenessInfo[]>

Proactively triggers screen content awareness to obtain the screen content for snapshot analysis.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

Parameters

NameTypeMandatoryDescription
capabilityOnscreenAwarenessCapYesOnscreen awareness capability list. For details, see the following supported capability list.
optionsOnscreenAwarenessOptionsNoOnscreen awareness parameter list.

groupId capabilities supported by the apperceive API

groupId CapabilitySub-capabilityFunction
SmartEdgeActicleObtains the information about awareness in a reading scenario.
SmartEdgeShortVideoObtains the information about awareness in a short video scenario.
SmartEdgeTodoObtains the information about awareness in a to-do scenario.
SmartEdgeActivityObtains the awareness information of basic services.

Return value

TypeDescription
Promise<OnscreenAwarenessInfo[]>Promise used to return the onscreen awareness result. The returned onscreen awareness information list OnscreenAwarenessInfo[] contains a maximum of two awareness information items.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.
34000002The application or page is not supported.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
let onscreenAwarenessCap: onScreen.OnscreenAwarenessCap = {
  groupId: 'SmartEdge'
}
try {
  let info: onScreen.OnscreenAwarenessInfo[] = await onScreen.apperceive(onscreenAwarenessCap);
  console.error(`apperceive resultCode: ${info[0].resultCode}`);
} catch (err) {
  console.info(`apperceive failed, error: ${err}`);
}

onScreen.onReadingScreenPermissionListener23+

onReadingScreenPermissionListener(callback: Callback<ReadingScreenPermissionStatus>): void

Enables the screen content access permission monitoring and returns the permission status in real time.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
callbackCallback<ReadingScreenPermissionStatus>YesCallback used to return the status of the permission for reading screen information.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
try {
   onScreen.onReadingScreenPermissionListener((info: onScreen.ReadingScreenPermissionStatus) => {
      console.info(`onReadingScreenPermissionListener succeeded, readingState: ${info.readingState}`);
   });
} catch (err) {
   console.error('onReadingScreenPermissionListener failed, errCode = ' + err.code);
}

onScreen.offReadingScreenPermissionListener23+

offReadingScreenPermissionListener(callback?: Callback<ReadingScreenPermissionStatus>): void

Disables the screen content access permission monitoring.

Required permissions: ohos.permission.GET_SCREEN_CONTENT

System capability: SystemCapability.MultimodalAwareness.OnScreenAwareness

Device behavior differences: This API can be properly called on phones and tablets. If it is called on other devices, error code 801 is returned.

Parameters

NameTypeMandatoryDescription
callbackCallback<ReadingScreenPermissionStatus>NoCallback to unregister. If this parameter is not passed, all callbacks of the event are unregistered.

Error codes

For details about the error codes, see Onscreen Awareness Error Codes and Universal Error Codes.

IDError Message
201Permission denied. An attempt was made to get page content forbidden by permission: ohos.permission.GET_SCREEN_CONTENT.
202Permission check failed. A non-system application uses the system API.
801Capability not supported. Function can not work correctly due to limited device capabilities.
34000001Service exception.

Example

import onScreen from "@ohos.multimodalAwareness.onScreen";
try {
  onScreen.offReadingScreenPermissionListener();
  console.info(`offReadingScreenPermissionListener succeeded.`);
} catch (err) {
  console.error('offReadingScreenPermissionListener failed, errCode = ' + err.code);
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 errorcode-onScreen

openharmony 鸿蒙 js-apis-awareness-metadataBinding-sys

openharmony 鸿蒙 errorcode-metadataBinding

openharmony 鸿蒙 js-apis-awareness-deviceStatus-sys

openharmony 鸿蒙 js-apis-awareness-motion

openharmony 鸿蒙 js-apis-awareness-metadataBinding

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 errorcode-userStatus

openharmony 鸿蒙 errorcode-deviceStatus

openharmony 鸿蒙 js-apis-stationary

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/PZEBqcxc