• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.AccessibilityExtensionAbility (AccessibilityExtensionAbility)
2
3The **AccessibilityExtensionAbility** module provides accessibility extension capabilities based on the ExtensionAbility framework.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility';
13```
14
15## Attributes
16
17**System capability**: SystemCapability.BarrierFree.Accessibility.Core
18
19| Name     | Type| Readable| Writable| Description                     |
20| --------- | -------- | ---- | ---- | ------------------------- |
21| context | [AccessibilityExtensionContext](js-apis-inner-application-accessibilityExtensionContext.md) | Yes| No| Context of the accessibility extension ability.|
22
23## AccessibilityEvent
24
25Defines an accessibility event.
26
27**System capability**: SystemCapability.BarrierFree.Accessibility.Core
28
29### Attributes
30
31| Name       | Type                                    | Readable  | Writable  | Description        |
32| --------- | ---------------------------------------- | ---- | ---- | ---------- |
33| eventType | [accessibility.EventType](js-apis-accessibility.md#EventType) \| [accessibility.WindowUpdateType](js-apis-accessibility.md#WindowUpdateType) \| [TouchGuideType](#touchguidetype) \| [GestureType](#gesturetype) \| [PageUpdateType](#pageupdatetype) | Yes   | No   | Event type.   |
34| target    | [AccessibilityElement](js-apis-inner-application-accessibilityExtensionContext.md#accessibilityelement9)                     | Yes   | No   | Target component where the event occurs.|
35| timeStamp | number                                   | Yes   | No   | Timestamp of the event.    |
36
37## GestureType
38
39Enumerates gesture types.
40
41**System capability**: SystemCapability.BarrierFree.Accessibility.Core
42
43| Name           | Description          |
44| ------------- | ------------ |
45| left          | Left gesture. String type. |
46| leftThenRight | Left-then-right gesture. String type. |
47| leftThenUp    | Left-then-up gesture. String type. |
48| leftThenDown  | Left-then-down gesture. String type. |
49| right         | Right gesture. String type. |
50| rightThenLeft | Right-then-left gesture. String type. |
51| rightThenUp   | Right-then-up gesture. String type. |
52| rightThenDown | Right-then-down gesture. String type. |
53| up            | Up gesture. String type. |
54| upThenLeft    | Up-then-left gesture. String type. |
55| upThenRight   | Up-then-right gesture. String type. |
56| upThenDown    | Up-then-down gesture. String type. |
57| down          | Down gesture. String type. |
58| downThenLeft  | Down-then-left gesture. String type. |
59| downThenRight | Down-then-right gesture. String type. |
60| downThenUp    | Down-then-up gesture. String type. |
61
62## PageUpdateType
63
64Enumerates the page update types.
65
66**System capability**: SystemCapability.BarrierFree.Accessibility.Core
67
68| Name               | Description       |
69| ----------------- | --------- |
70| pageContentUpdate | Update of the page content. String type. |
71| pageStateUpdate   | Update of the page status. String type. |
72
73## TouchGuideType
74
75Enumerates the touch guide event types.
76
77**System capability**: SystemCapability.BarrierFree.Accessibility.Core
78
79| Name        | Description          |
80| ---------- | ------------ |
81| touchBegin | Start of touch in touch guide mode. String type. |
82| touchEnd   | End of touch in touch guide mode. String type. |
83
84## AccessibilityExtensionAbility.onConnect
85
86onConnect(): void;
87
88Called when the **AccessibilityExtensionAbility** is enabled and connected to the system service. In this API, you can have the service logic initialized. This API can be overridden as required.
89
90**System capability**: SystemCapability.BarrierFree.Accessibility.Core
91
92**Example**
93
94```ts
95class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
96    onConnect() {
97        console.log('AxExtensionAbility onConnect');
98    }
99};
100```
101
102## AccessibilityExtensionAbility.onDisconnect
103
104onDisconnect(): void;
105
106Called when the **AccessibilityExtensionAbility** is disabled and disconnected from the system service. In this API, you can implement the service logic of resource release and exit. This API can be overridden as required.
107
108**System capability**: SystemCapability.BarrierFree.Accessibility.Core
109
110**Example**
111
112```ts
113class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
114    onDisconnect() {
115        console.log('AxExtensionAbility onDisconnect');
116    }
117};
118```
119
120## AccessibilityExtensionAbility.onAccessibilityEvent
121
122onAccessibilityEvent(event: AccessibilityEvent): void;
123
124Called when an event that matches the specified bundle and event type occurs. In this API, you can implement event-specific service logic. Generally, this API needs to be overridden.
125
126**System capability**: SystemCapability.BarrierFree.Accessibility.Core
127
128**Parameters**
129
130| Name  | Type                                    | Mandatory  | Description             |
131| ----- | ---------------------------------------- | ---- | --------------- |
132| event | [AccessibilityEvent](#accessibilityevent) | Yes   | Accessibility event. No value is returned.|
133
134**Example**
135
136```ts
137class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
138    onAccessibilityEvent(event) {
139        console.log('AxExtensionAbility onAccessibilityEvent');
140        if (event.eventType === 'click') {
141            console.log('AxExtensionAbility onAccessibilityEvent: click');
142        }
143    }
144};
145```
146
147## AccessibilityExtensionAbility.onKeyEvent
148
149onKeyEvent(keyEvent: KeyEvent): boolean;
150
151Called when a physical key is pressed. In this API, you can determine whether to intercept an event based on the service.
152
153**System capability**: SystemCapability.BarrierFree.Accessibility.Core
154
155**Parameters**
156
157| Name     | Type                                    | Mandatory  | Description                     |
158| -------- | ---------------------------------------- | ---- | ----------------------- |
159| keyEvent | [KeyEvent](js-apis-keyevent.md#KeyEvent) | Yes   | Key event. If **true** is returned, the key is intercepted.|
160
161**Example**
162
163```ts
164class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
165    onKeyEvent(keyEvent) {
166        console.log('AxExtensionAbility onKeyEvent');
167        if (keyEvent.keyCode === 22) {
168            console.log('AxExtensionAbility onKeyEvent: intercept 22');
169            return true;
170        }
171        return false;
172    }
173};
174```
175