js-apis-application-accessibilityExtensionAbility.md 6.4 KB
Newer Older
G
Gloria 已提交
1
# @ohos.application.AccessibilityExtensionAbility (AccessibilityExtensionAbility)
E
ester.zhou 已提交
2

E
esterzhou 已提交
3
The **AccessibilityExtensionAbility** module provides accessibility extension capabilities based on the ExtensionAbility framework.
E
ester.zhou 已提交
4

E
esterzhou 已提交
5
> **NOTE**
E
ester.zhou 已提交
6
>
E
esterzhou 已提交
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.
E
ester.zhou 已提交
8 9 10 11

## Modules to Import

```ts
E
ester.zhou 已提交
12
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility';
E
ester.zhou 已提交
13 14
```

15 16 17 18
## Attributes

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

E
esterzhou 已提交
19
| Name     | Type| Readable| Writable| Description                     |
20
| --------- | -------- | ---- | ---- | ------------------------- |
E
esterzhou 已提交
21
| context | [AccessibilityExtensionContext](js-apis-inner-application-accessibilityExtensionContext.md) | Yes| No| Context of the accessibility extension ability.|
22

E
ester.zhou 已提交
23 24 25 26 27 28 29 30 31 32
## AccessibilityEvent

Defines an accessibility event.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

### Attributes

| Name       | Type                                    | Readable  | Writable  | Description        |
| --------- | ---------------------------------------- | ---- | ---- | ---------- |
E
esterzhou 已提交
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.   |
E
ester.zhou 已提交
34
| target    | [AccessibilityElement](js-apis-inner-application-accessibilityExtensionContext.md#accessibilityelement9)                     | Yes   | No   | Target component where the event occurs.|
E
ester.zhou 已提交
35 36 37 38 39 40 41 42 43 44
| timeStamp | number                                   | Yes   | No   | Timestamp of the event.    |

## GestureType

Enumerates gesture types.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name           | Description          |
| ------------- | ------------ |
E
ester.zhou 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| left          | Left gesture. String type. |
| leftThenRight | Left-then-right gesture. String type. |
| leftThenUp    | Left-then-up gesture. String type. |
| leftThenDown  | Left-then-down gesture. String type. |
| right         | Right gesture. String type. |
| rightThenLeft | Right-then-left gesture. String type. |
| rightThenUp   | Right-then-up gesture. String type. |
| rightThenDown | Right-then-down gesture. String type. |
| up            | Up gesture. String type. |
| upThenLeft    | Up-then-left gesture. String type. |
| upThenRight   | Up-then-right gesture. String type. |
| upThenDown    | Up-then-down gesture. String type. |
| down          | Down gesture. String type. |
| downThenLeft  | Down-then-left gesture. String type. |
| downThenRight | Down-then-right gesture. String type. |
| downThenUp    | Down-then-up gesture. String type. |
E
ester.zhou 已提交
61 62 63

## PageUpdateType

E
esterzhou 已提交
64
Enumerates the page update types.
E
ester.zhou 已提交
65 66 67 68 69

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name               | Description       |
| ----------------- | --------- |
E
ester.zhou 已提交
70 71
| pageContentUpdate | Update of the page content. String type. |
| pageStateUpdate   | Update of the page status. String type. |
E
ester.zhou 已提交
72 73 74 75 76 77 78 79 80

## TouchGuideType

Enumerates the touch guide event types.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name        | Description          |
| ---------- | ------------ |
E
ester.zhou 已提交
81 82
| touchBegin | Start of touch in touch guide mode. String type. |
| touchEnd   | End of touch in touch guide mode. String type. |
E
ester.zhou 已提交
83 84 85 86 87

## AccessibilityExtensionAbility.onConnect

onConnect(): void;

E
esterzhou 已提交
88
Called 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.
E
ester.zhou 已提交
89 90 91 92 93 94

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Example**

```ts
E
esterzhou 已提交
95 96 97 98 99
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
    onConnect() {
        console.log('AxExtensionAbility onConnect');
    }
};
E
ester.zhou 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112
```

## AccessibilityExtensionAbility.onDisconnect

onDisconnect(): void;

Called 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.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Example**

```ts
E
esterzhou 已提交
113 114 115 116 117
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
    onDisconnect() {
        console.log('AxExtensionAbility onDisconnect');
    }
};
E
ester.zhou 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131
```

## AccessibilityExtensionAbility.onAccessibilityEvent

onAccessibilityEvent(event: AccessibilityEvent): void;

Called 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.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name  | Type                                    | Mandatory  | Description             |
| ----- | ---------------------------------------- | ---- | --------------- |
132
| event | [AccessibilityEvent](#accessibilityevent) | Yes   | Accessibility event. No value is returned.|
E
ester.zhou 已提交
133 134 135 136

**Example**

```ts
E
esterzhou 已提交
137 138 139
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
    onAccessibilityEvent(event) {
        console.log('AxExtensionAbility onAccessibilityEvent');
E
ester.zhou 已提交
140
        if (event.eventType === 'click') {
E
esterzhou 已提交
141 142
            console.log('AxExtensionAbility onAccessibilityEvent: click');
        }
E
ester.zhou 已提交
143
    }
E
esterzhou 已提交
144
};
E
ester.zhou 已提交
145 146 147 148
```

## AccessibilityExtensionAbility.onKeyEvent

E
esterzhou 已提交
149
onKeyEvent(keyEvent: KeyEvent): boolean;
E
ester.zhou 已提交
150

E
esterzhou 已提交
151
Called when a physical key is pressed. In this API, you can determine whether to intercept an event based on the service.
E
ester.zhou 已提交
152 153 154 155 156 157 158

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name     | Type                                    | Mandatory  | Description                     |
| -------- | ---------------------------------------- | ---- | ----------------------- |
159
| keyEvent | [KeyEvent](js-apis-keyevent.md#KeyEvent) | Yes   | Key event. If **true** is returned, the key is intercepted.|
E
ester.zhou 已提交
160 161 162 163

**Example**

```ts
E
esterzhou 已提交
164 165 166
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
    onKeyEvent(keyEvent) {
        console.log('AxExtensionAbility onKeyEvent');
E
ester.zhou 已提交
167
        if (keyEvent.keyCode === 22) {
E
esterzhou 已提交
168 169 170 171
            console.log('AxExtensionAbility onKeyEvent: intercept 22');
            return true;
        }
        return false;
E
ester.zhou 已提交
172
    }
E
esterzhou 已提交
173
};
E
ester.zhou 已提交
174
```