提交 05139a01 编写于 作者: G Gloria

Update docs against 15402

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 874ddfa3
...@@ -16,6 +16,10 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md ...@@ -16,6 +16,10 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md
| ohos.vibrator | startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void | Starts vibration with the specified effect and attribute. This API uses an asynchronous callback to return the result.| | ohos.vibrator | startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void | Starts vibration with the specified effect and attribute. This API uses an asynchronous callback to return the result.|
| ohos.vibrator | stopVibration(stopMode: VibratorStopMode): Promise&lt;void&gt; | Stops vibration in the specified mode. This API uses a promise to return the result. | | ohos.vibrator | stopVibration(stopMode: VibratorStopMode): Promise&lt;void&gt; | Stops vibration in the specified mode. This API uses a promise to return the result. |
| ohos.vibrator | stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback&lt;void&gt;): void | Stops vibration in the specified mode. This API uses an asynchronous callback to return the result. | | ohos.vibrator | stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback&lt;void&gt;): void | Stops vibration in the specified mode. This API uses an asynchronous callback to return the result. |
| ohos.vibrator | stopVibration(): Promise&lt;void&gt; | Stops vibration in all modes. This API uses a promise to return the result. |
| ohos.vibrator | stopVibration(callback: AsyncCallback&lt;void&gt;): void | Stops vibration in all modes. This API uses an asynchronous callback to return the result. |
| ohos.vibrator | isSupportEffect(effectId: string): Promise&lt;boolean&gt; | Checks whether the passed effect ID is supported. This API uses a promise to return the result. The value **true** means that the passed effect ID is supported, and **false** means the opposite. |
| ohos.vibrator | isSupportEffect(effectId: string, callback: AsyncCallback&lt;boolean&gt;): void | Checks whether the passed effect ID is supported. This API uses an asynchronous callback to return the result. The value **true** means that the passed effect ID is supported, and **false** means the opposite. |
## How to Develop ## How to Develop
...@@ -27,7 +31,7 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md ...@@ -27,7 +31,7 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md
```js ```js
import vibrator from '@ohos.vibrator'; import vibrator from '@ohos.vibrator';
try { try {
vibrator.startVibration({ vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission.
type: 'time', type: 'time',
duration: 1000, duration: 1000,
}, { }, {
...@@ -50,7 +54,7 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md ...@@ -50,7 +54,7 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md
```js ```js
import vibrator from '@ohos.vibrator'; import vibrator from '@ohos.vibrator';
try { try {
// Stop vibration in VIBRATOR_STOP_MODE_TIME mode. // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. To use stopVibration, you must configure the ohos.permission.VIBRATE permission.
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) { vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) {
if (error) { if (error) {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
...@@ -62,3 +66,72 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md ...@@ -62,3 +66,72 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md
console.info('errCode: ' + err.code + ' ,msg: ' + err.message); console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
} }
``` ```
4. Stop vibration in all modes.
```js
import vibrator from '@ohos.vibrator';
// To use startVibration and stopVibration, you must configure the ohos.permission.VIBRATE permission.
try {
vibrator.startVibration({
type: 'time',
duration: 1000,
}, {
id: 0,
usage: 'alarm'
}, (error) => {
if (error) {
console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message);
return;
}
console.log('Callback returned to indicate a successful vibration.');
});
// Stop vibration in all modes.
vibrator.stopVibration(function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message);
return;
}
console.log('Callback returned to indicate successful.');
})
} catch (error) {
console.info('errCode: ' + error.code + ' ,msg: ' + error.message);
}
```
5. Check whether the passed effect ID is supported.
```js
import vibrator from '@ohos.vibrator';
try {
// Check whether 'haptic.clock.timer' is supported.
vibrator.isSupportEffect('haptic.clock.timer', function (err, state) {
if (err) {
console.error('isSupportEffect failed, error:' + JSON.stringify(err));
return;
}
console.log('The effectId is ' + (state ? 'supported' : 'unsupported'));
if (state) {
try {
vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission.
type: 'preset',
effectId: 'haptic.clock.timer',
count: 1,
}, {
usage: 'unknown'
}, (error) => {
if(error) {
console.error('haptic.clock.timer vibrator error:' + JSON.stringify(error));
} else {
console.log('haptic.clock.timer vibrator success');
}
});
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
}
})
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
```
...@@ -42,6 +42,7 @@ For details about the error codes, see [Vibrator Error Codes](../errorcodes/erro ...@@ -42,6 +42,7 @@ For details about the error codes, see [Vibrator Error Codes](../errorcodes/erro
**Example** **Example**
```js ```js
import vibrator from '@ohos.vibrator';
try { try {
vibrator.startVibration({ vibrator.startVibration({
type: 'time', type: 'time',
...@@ -95,6 +96,7 @@ For details about the error codes, see [Vibrator Error Codes](../errorcodes/erro ...@@ -95,6 +96,7 @@ For details about the error codes, see [Vibrator Error Codes](../errorcodes/erro
**Example** **Example**
```js ```js
import vibrator from '@ohos.vibrator';
try { try {
vibrator.startVibration({ vibrator.startVibration({
type: 'time', type: 'time',
...@@ -132,6 +134,7 @@ Stops vibration in the specified mode. This API uses an asynchronous callback to ...@@ -132,6 +134,7 @@ Stops vibration in the specified mode. This API uses an asynchronous callback to
**Example** **Example**
```js ```js
import vibrator from '@ohos.vibrator';
try { try {
// Start vibration at a fixed duration. // Start vibration at a fixed duration.
vibrator.startVibration({ vibrator.startVibration({
...@@ -190,6 +193,7 @@ Stops vibration in the specified mode. This API uses a promise to return the res ...@@ -190,6 +193,7 @@ Stops vibration in the specified mode. This API uses a promise to return the res
**Example** **Example**
```js ```js
import vibrator from '@ohos.vibrator';
try { try {
// Start vibration at a fixed duration. // Start vibration at a fixed duration.
vibrator.startVibration({ vibrator.startVibration({
...@@ -219,6 +223,213 @@ try { ...@@ -219,6 +223,213 @@ try {
} }
``` ```
## vibrator.stopVibration<sup>10+</sup>
stopVibration(callback: AsyncCallback&lt;void&gt;): void
Stops vibration in all modes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the vibration stops, **err** is **undefined**; otherwise, **err** is an error object.|
**Example**
```js
import vibrator from '@ohos.vibrator';
try {
// Start vibration at a fixed duration.
vibrator.startVibration({
type: 'time',
duration: 1000,
}, {
id: 0,
usage: 'alarm'
}, (error) => {
if (error) {
console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message);
return;
}
console.log('Callback returned to indicate a successful vibration.');
});
} catch (error) {
console.error('errCode: ' + error.code + ' ,msg: ' + error.message);
}
try {
// Stop vibration in all modes.
vibrator.stopVibration(function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message);
return;
}
console.log('Callback returned to indicate successful.');
})
} catch (error) {
console.info('errCode: ' + error.code + ' ,msg: ' + error.message);
}
```
## vibrator.stopVibration<sup>10+</sup>
stopVibration(): Promise&lt;void&gt;
Stops vibration in all modes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
import vibrator from '@ohos.vibrator';
try {
// Start vibration at a fixed duration.
vibrator.startVibration({
type: 'time',
duration: 1000
}, {
id: 0,
usage: 'alarm'
}).then(() => {
console.log('Promise returned to indicate a successful vibration');
}, (error) => {
console.error('error.code' + error.code + 'error.message' + error.message);
});
} catch (error) {
console.error('errCode: ' + error.code + ' ,msg: ' + error.message);
}
try {
// Stop vibration in all modes.
vibrator.stopVibration().then(() => {
console.log('Promise returned to indicate a successful vibration.');
}, (error) => {
console.log('error.code' + error.code + 'error.message' + error.message);
});
} catch (error) {
console.info('errCode: ' + error.code + ' ,msg: ' + error.message);
}
```
## vibrator.isSupportEffect<sup>10+</sup>
isSupportEffect(effectId: string, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the passed effect ID is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| effectId | string | Yes | Vibration effect ID. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. The value **true** means that the passed effect ID is supported, and **false** means the opposite. |
**Example**
```js
import vibrator from '@ohos.vibrator';
try {
// Check whether 'haptic.clock.timer' is supported.
vibrator.isSupportEffect('haptic.clock.timer', function (err, state) {
if (err) {
console.error('isSupportEffect failed, error:' + JSON.stringify(err));
return;
}
console.log('The effectId is ' + (state ? 'supported' : 'unsupported'));
if (state) {
try {
vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission.
type: 'preset',
effectId: 'haptic.clock.timer',
count: 1,
}, {
usage: 'unknown'
}, (error) => {
if(error) {
console.error('haptic.clock.timer vibrator error:' + JSON.stringify(error));
} else {
console.log('haptic.clock.timer vibrator success');
}
});
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
}
})
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
```
## vibrator.isSupportEffect<sup>10+</sup>
isSupportEffect(effectId: string): Promise&lt;boolean&gt;
Checks whether the passed effect ID is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------ |
| effectId | string | Yes | Vibration effect ID.|
**Return value**
| Type | Description |
| ---------------------- | --------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise that returns the result. The value **true** means that the passed effect ID is supported, and **false** means the opposite. |
**Example**
```js
import vibrator from '@ohos.vibrator';
try {
// Check whether 'haptic.clock.timer' is supported.
vibrator.isSupportEffect('haptic.clock.timer').then((state) => {
console.log('The effectId is ' + (state ? 'supported' : 'unsupported'));
if (state) {
try {
vibrator.startVibration({
type: 'preset',
effectId: 'haptic.clock.timer',
count: 1,
}, {
usage: 'unknown'
}).then(()=>{
console.log('Promise returned to indicate a successful vibration');
}).catch((error)=>{
console.error('Promise returned to indicate a failed vibration:' + JSON.stringify(error));
});
} catch (error) {
console.error('exception in, error:' + JSON.stringify(error));
}
}
}, (error) => {
console.error('isSupportEffect failed, error:' + JSON.stringify(error));
})
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
```
## EffectId ## EffectId
Describes the preset vibration effect ID. Describes the preset vibration effect ID.
......
# Pan-sensor Subsystem Changelog
## cl.vibrator Added isSupportEffect
The **isSupportEffect** API is added.
**Change Impact**
Applications developed based on OpenHarmony4.0.5.2 or a later SDK version can use **isSupportEffect** to check whether the passed effect ID is supported.
**Key API/Component Changes**
The **isSupportEffect** API is added in **@ohos.vibrator.d.ts**.
| Module| Class| Method/Attribute/Enum/Constant| Change Type|
| -- | -- | -- | -- |
| @ohos.vibrator.d.ts | vibrator | isSupportEffect(effectId: string, callback: AsyncCallback&lt;boolean&gt;): void | Added|
| @ohos.vibrator.d.ts | vibrator | isSupportEffect(effectId: string): Promise&lt;boolean&gt; | Added|
**Adaptation Guide**
Call **isSupportEffect** to check whether the passed effect ID is supported.
```ts
import vibrator from '@ohos.vibrator';
try {
// Check whether 'haptic.clock.timer' is supported.
vibrator.isSupportEffect('haptic.clock.timer', function (err, state) {
if (err) {
console.error('isSupportEffect failed, error:' + JSON.stringify(err));
return;
}
console.log('The effectId is ' + (state ? 'supported' : 'unsupported'));
if (state) {
try {
vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission.
type: 'preset',
effectId: 'haptic.clock.timer',
count: 1,
}, {
usage: 'unknown'
}, (error) => {
if(error) {
console.error('haptic.clock.timer vibrator error:' + JSON.stringify(error));
} else {
console.log('haptic.clock.timer vibrator success');
}
});
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
}
})
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
```
## cl.vibrator Added stopVibration
The **stopVibration** API is added.
**Change Impact**
Applications developed based on OpenHarmony4.0.5.2 or a later SDK version can use **stopVibration** to stop vibration in all modes.
**Key API/Component Changes**
The **stopVibration** API is added in **@ohos.vibrator.d.ts**.
| Module | Class | Method/Attribute/Enum/Constant | Change Type|
| ------------------- | -------- | -------------------------------------------------------- | -------- |
| @ohos.vibrator.d.ts | vibrator | stopVibration(callback: AsyncCallback&lt;void&gt;): void | Added |
| @ohos.vibrator.d.ts | vibrator | stopVibration(): Promise&lt;void&gt; | Added |
**Adaptation Guide**
Call **stopVibration** to stop vibration in all modes.
```ts
import vibrator from '@ohos.vibrator';
try {
// Stop vibration in all modes.
vibrator.stopVibration(function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message);
return;
}
console.log('Callback returned to indicate successful.');
})
} catch (error) {
console.info('errCode: ' + error.code + ' ,msg: ' + error.message);
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册