js-apis-application-accessibilityExtensionAbility.md 6.1 KB
Newer Older
E
esterzhou 已提交
1
# @ohos.application.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 12 13 14

## Modules to Import

```ts
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'
```

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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| target    | AccessibilityElement                     | Yes   | No   | Target component where the event occurs.|
| timeStamp | number                                   | Yes   | No   | Timestamp of the event.    |

## GestureType

Enumerates gesture types.

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

| Name           | Description          |
| ------------- | ------------ |
| left          | Left gesture.    |
| leftThenRight | Left-then-right gesture.|
| leftThenUp    | Left-then-up gesture.|
| leftThenDown  | Left-then-down gesture.|
| right         | Right gesture.    |
| rightThenLeft | Right-then-left gesture.|
| rightThenUp   | Right-then-up gesture.|
| rightThenDown | Right-then-down gesture.|
| up            | Up gesture.    |
| upThenLeft    | Up-then-left gesture.|
| upThenRight   | Up-then-right gesture.|
| upThenDown    | Up-then-down gesture.|
| down          | Down gesture.    |
| downThenLeft  | Down-then-left gesture.|
| downThenRight | Down-then-right gesture.|
| downThenUp    | Down-then-up gesture.|

## PageUpdateType

E
esterzhou 已提交
64
Enumerates the page update types.
E
ester.zhou 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

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

| Name               | Description       |
| ----------------- | --------- |
| pageContentUpdate | Update of the page content.|
| pageStateUpdate   | Update of the page status.|

## TouchGuideType

Enumerates the touch guide event types.

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

| Name        | Description          |
| ---------- | ------------ |
E
esterzhou 已提交
81 82
| touchBegin | Start of touch in touch guide mode. |
| touchEnd   | End of touch in touch guide mode. |
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 140 141 142
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
    onAccessibilityEvent(event) {
        console.log('AxExtensionAbility onAccessibilityEvent');
        if (event.eventType == 'click') {
            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 167 168 169 170 171
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
    onKeyEvent(keyEvent) {
        console.log('AxExtensionAbility onKeyEvent');
        if (keyEvent.keyCode == 22) {
            console.log('AxExtensionAbility onKeyEvent: intercept 22');
            return true;
        }
        return false;
E
ester.zhou 已提交
172
    }
E
esterzhou 已提交
173
};
E
ester.zhou 已提交
174
```