提交 41b33de5 编写于 作者: W wangkai

arkts check

Signed-off-by: Nwangkai <wangkai424@huawei.com>
上级 61b7ef48
......@@ -54,12 +54,13 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
2. 创建一个统一数据对象并插入到UDMF的公共数据通路中。
```ts
import { BusinessError } from '@ohos.base';
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'hello world!';
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
// 指定要插入数据的数据通路枚举类型
let options = {
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
}
try {
......@@ -70,19 +71,21 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
}
});
} catch(e) {
console.error(`Insert data throws an exception. code is ${e.code},message is ${e.message} `);
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
3. 更新上一步骤插入的统一数据对象。
```ts
import { BusinessError } from '@ohos.base';
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'How are you!';
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
// 指定要更新的统一数据对象的URI
let options = {
let options: unifiedDataChannel.Options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
};
......@@ -94,15 +97,17 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
console.error(`Failed to update data. code is ${err.code},message is ${err.message} `);
}
});
} catch(e) {
console.error(`Update data throws an exception. code is ${e.code},message is ${e.message} `);
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
4. 删除存储在UDMF公共数据通路中的统一数据对象。
```ts
import { BusinessError } from '@ohos.base';
// 指定要删除数据的数据通路枚举类型
let options = {
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
};
......@@ -114,7 +119,7 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = <unifiedDataChannel.PlainText>(records[j]);
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}
......@@ -123,8 +128,9 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
}
});
} catch(e) {
console.error(`Delete data throws an exception. code is ${e.code},message is ${e.message} `);
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Delete data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
......@@ -139,8 +145,9 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
2. 查询存储在UDMF公共数据通路中的统一数据对象。
```ts
import { BusinessError } from '@ohos.base';
// 指定要查询数据的数据通路枚举类型
let options = {
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
};
......@@ -152,7 +159,7 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = <unifiedDataChannel.PlainText>(records[j]);
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}
......@@ -162,6 +169,7 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
}
});
} catch(e) {
console.error(`Query data throws an exception. code is ${e.code},message is ${e.message} `);
let error: BusinessError = e as BusinessError;
console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
......@@ -114,11 +114,11 @@ UDMF提供了统一数据对象UnifiedData,用于封装一组数据记录Unifi
switch (type) {
case uniformTypeDescriptor.UniformDataType.IMAGE:
// 转换得到原图片数据记录
let image = <unifiedDataChannel.Image>(records[i]);
let image = records[i] as unifiedDataChannel.Image;
break;
case uniformTypeDescriptor.UniformDataType.PLAIN_TEXT:
// 转换得到原文本数据记录
let plainText = <unifiedDataChannel.PlainText>(records[i]);
let plainText = records[i] as unifiedDataChannel.PlainText;
break;
default:
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册