提交 e3012776 编写于 作者: L lixiangpeng5

fix code space

Signed-off-by: Nlixiangpeng5 <lixiangpeng5@huawei.com>
Change-Id: Ib2dddacb47ad221eb4c1b5e60ee1151d6d134ece
上级 b089f774
...@@ -254,12 +254,12 @@ Json共包含2个属性。"MetaData":文件头信息,可在相应属性中 ...@@ -254,12 +254,12 @@ Json共包含2个属性。"MetaData":文件头信息,可在相应属性中
6. 启动和停止自定义振动 6. 启动和停止自定义振动
```js ```js
import vibrator from '@ohos.vibrator'; import vibrator from '@ohos.vibrator';
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
const FILE_NAME = "xxx.json"; const FILE_NAME = "xxx.json";
async function openResource(fileName) { async function openResource(fileName) {
let fileDescriptor = undefined; let fileDescriptor = undefined;
let mgr = await resourceManager.getResourceManager(); let mgr = await resourceManager.getResourceManager();
await mgr.getRawFd(fileName).then(value => { await mgr.getRawFd(fileName).then(value => {
...@@ -269,21 +269,21 @@ Json共包含2个属性。"MetaData":文件头信息,可在相应属性中 ...@@ -269,21 +269,21 @@ Json共包含2个属性。"MetaData":文件头信息,可在相应属性中
console.log('openResource err: ' + error); console.log('openResource err: ' + error);
}); });
return fileDescriptor; return fileDescriptor;
} }
async function closeResource(fileName) { async function closeResource(fileName) {
let mgr = await resourceManager.getResourceManager(); let mgr = await resourceManager.getResourceManager();
await mgr.closeRawFd(fileName).then(()=> { await mgr.closeRawFd(fileName).then(()=> {
console.log('closeResource success fileName: ' + fileName); console.log('closeResource success fileName: ' + fileName);
}).catch(error => { }).catch(error => {
console.log('closeResource err: ' + error); console.log('closeResource err: ' + error);
}); });
} }
// 获取振动文件资源描述符 // 获取振动文件资源描述符
let rawFd = openResource(FILE_NAME); let rawFd = openResource(FILE_NAME);
// 使用startVibration、stopVibration需要添加ohos.permission.VIBRATE权限 // 使用startVibration、stopVibration需要添加ohos.permission.VIBRATE权限
try { try {
// 启动自定义振动 // 启动自定义振动
vibrator.startVibration({ vibrator.startVibration({
type: "file", type: "file",
...@@ -303,11 +303,11 @@ Json共包含2个属性。"MetaData":文件头信息,可在相应属性中 ...@@ -303,11 +303,11 @@ Json共包含2个属性。"MetaData":文件头信息,可在相应属性中
} }
console.log('Callback returned to indicate successful.'); console.log('Callback returned to indicate successful.');
}) })
} catch (error) { } catch (error) {
console.info('errCode: ' + error.code + ' ,msg: ' + error.message); console.info('errCode: ' + error.code + ' ,msg: ' + error.message);
} }
// 关闭振动文件资源 // 关闭振动文件资源
closeResource(FILE_NAME); closeResource(FILE_NAME);
``` ```
## 相关实例 ## 相关实例
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册