js-apis-ability-dataUriUtils.md 3.1 KB
Newer Older
1
# @ohos.ability.dataUriUtils (dataUriUtils)
2

3
The **DataUriUtils** module provides APIs to process URI objects. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI. This module will be replaced by the **app.ability.dataUriUtils** module in the near future. You are advised to use the **[@ohos.app.ability.dataUriUtils](js-apis-app-ability-dataUriUtils.md)** module.
W
wusongqing 已提交
4

W
wusongqing 已提交
5 6
> **NOTE**
> 
W
wusongqing 已提交
7 8
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.

W
wusongqing 已提交
9 10
## Modules to Import

11
```ts
W
wusongqing 已提交
12 13 14
import dataUriUtils from '@ohos.ability.dataUriUtils';
```

W
wusongqing 已提交
15
## dataUriUtils.getId
W
wusongqing 已提交
16

W
wusongqing 已提交
17
getId(uri: string): number
W
wusongqing 已提交
18

W
wusongqing 已提交
19
Obtains the ID attached to the end of a given URI.
W
wusongqing 已提交
20

W
wusongqing 已提交
21
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
22

W
wusongqing 已提交
23
**Parameters**
W
wusongqing 已提交
24

W
wusongqing 已提交
25
| Name| Type  | Mandatory| Description                       |
W
wusongqing 已提交
26
| ---- | ------ | ---- | --------------------------- |
27
| uri  | string | Yes  | Target URI object.|
W
wusongqing 已提交
28

W
wusongqing 已提交
29
**Return value**
W
wusongqing 已提交
30

W
wusongqing 已提交
31
| Type  | Description                    |
W
wusongqing 已提交
32
| ------ | ------------------------ |
33
| number | ID obtained.|
W
wusongqing 已提交
34

W
wusongqing 已提交
35
**Example**
W
wusongqing 已提交
36

37
```ts
38
let id = dataUriUtils.getId('com.example.dataUriUtils/1221');
W
wusongqing 已提交
39 40 41 42
```



W
wusongqing 已提交
43
## dataUriUtils.attachId
W
wusongqing 已提交
44

W
wusongqing 已提交
45
attachId(uri: string, id: number): string
W
wusongqing 已提交
46

W
wusongqing 已提交
47
Attaches an ID to the end of a given URI.
W
wusongqing 已提交
48

W
wusongqing 已提交
49
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
50

W
wusongqing 已提交
51
**Parameters**
W
wusongqing 已提交
52

W
wusongqing 已提交
53
| Name| Type  | Mandatory| Description                       |
W
wusongqing 已提交
54
| ---- | ------ | ---- | --------------------------- |
55
| uri  | string | Yes  | Target URI object.|
W
wusongqing 已提交
56
| id   | number | Yes  | ID to be attached.           |
W
wusongqing 已提交
57

W
wusongqing 已提交
58
**Return value**
W
wusongqing 已提交
59

W
wusongqing 已提交
60
| Type  | Description                 |
W
wusongqing 已提交
61
| ------ | --------------------- |
W
wusongqing 已提交
62
| string | URI object with the ID attached.|
W
wusongqing 已提交
63

W
wusongqing 已提交
64
**Example**
W
wusongqing 已提交
65

66 67 68
```ts
let id = 1122;
let uri = dataUriUtils.attachId(
69
    'com.example.dataUriUtils',
70
	id,
71
);
W
wusongqing 已提交
72 73 74 75
```



W
wusongqing 已提交
76
## dataUriUtils.deleteId
W
wusongqing 已提交
77

W
wusongqing 已提交
78
deleteId(uri: string): string
W
wusongqing 已提交
79

W
wusongqing 已提交
80
Deletes the ID from the end of a given URI.
W
wusongqing 已提交
81

W
wusongqing 已提交
82 83
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
84
**Parameters**
W
wusongqing 已提交
85

W
wusongqing 已提交
86
| Name| Type  | Mandatory| Description                       |
W
wusongqing 已提交
87
| ---- | ------ | ---- | --------------------------- |
W
wusongqing 已提交
88
| uri  | string | Yes  | URI object from which the ID is to be deleted.|
W
wusongqing 已提交
89

W
wusongqing 已提交
90
**Return value**
W
wusongqing 已提交
91

W
wusongqing 已提交
92
| Type  | Description               |
W
wusongqing 已提交
93
| ------ | ------------------- |
W
wusongqing 已提交
94
| string | URI object with the ID deleted.|
W
wusongqing 已提交
95

W
wusongqing 已提交
96
**Example**
W
wusongqing 已提交
97

98
```ts
99
let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');
W
wusongqing 已提交
100 101 102 103
```



W
wusongqing 已提交
104
## dataUriUtils.updateId
W
wusongqing 已提交
105

W
wusongqing 已提交
106
updateId(uri: string, id: number): string
W
wusongqing 已提交
107

W
wusongqing 已提交
108
Updates the ID in a given URI.
W
wusongqing 已提交
109

W
wusongqing 已提交
110 111
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
112
**Parameters**
W
wusongqing 已提交
113

W
wusongqing 已提交
114
| Name| Type  | Mandatory| Description               |
W
wusongqing 已提交
115
| ---- | ------ | ---- | ------------------- |
116
| uri  | string | Yes  | Target URI object.|
W
wusongqing 已提交
117
| id   | number | Yes  | New ID.           |
W
wusongqing 已提交
118

W
wusongqing 已提交
119
**Return value**
W
wusongqing 已提交
120

W
wusongqing 已提交
121
| Type  | Description           |
W
wusongqing 已提交
122
| ------ | --------------- |
W
wusongqing 已提交
123
| string | URI object with the new ID.|
W
wusongqing 已提交
124

W
wusongqing 已提交
125
**Example**
W
wusongqing 已提交
126

127 128 129
```ts
let id = 1122;
let uri = dataUriUtils.updateId(
130
    'com.example.dataUriUtils/1221',
131
	id
132
);
W
wusongqing 已提交
133
```