• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# uriPermissionManager
2
3> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
4> 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.
5
6
7Implements URI permission management.
8
9
10## Modules to Import
11
12
13```
14import uriPermissionManager from '@ohos.application.uriPermissionManager';
15```
16
17
18## uriPermissionManager.verifyUriPermission
19
20verifyUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number, callback: AsyncCallback<number>): void
21
22Checks whether an application has the permission specified by **flag** for an URI. This API uses a callback to return the result.
23
24**System capability**:
25
26SystemCapability.Ability.AbilityRuntime.Core
27
28**Parameters**
29
30  | Name| Type| Mandatory| Description|
31  | -------- | -------- | -------- | -------- |
32  | uri | string | Yes| URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**.|
33  | flag | wantConstant.Flags | Yes| Read or write permission on the file specified by the URI.|
34  | accessTokenId | number | Yes| Unique ID of an application, which is obtained through the **BundleManager** API.|
35  | callback | AsyncCallback<number> | Yes| Callback used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite.|
36
37**Example**
38
39  ```
40  let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
41  UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => {
42      console.log("result.code = " + result.code)
43  }) // accessTokenId is obtained through the **BundleManager** API.
44  ```
45
46
47## uriPermissionManager.verifyUriPermission
48
49verifyUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number): Promise<number>
50
51Checks whether an application has the permission specified by **flag** for an URI. This API uses a promise to return the result.
52
53**System capability**:
54
55SystemCapability.Ability.AbilityRuntime.Core
56
57**Parameters**
58
59  | Name| Type| Mandatory| Description|
60  | -------- | -------- | -------- | -------- |
61  | uri | string | Yes| URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**.|
62  | flag | wantConstant.Flags | Yes| Read or write permission on the file specified by the URI.|
63  | accessTokenId | number | Yes| Unique ID of an application, which is obtained through the **BundleManager** API.|
64
65**Return value**
66
67  | Type| Description|
68  | -------- | -------- |
69  | Promise<number> | Promise used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite.|
70
71**Example**
72
73  ```
74  let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
75  UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId)
76  .then((data) => {
77      console.log('Verification succeeded.' + data)
78  }).catch((error) => {
79      console.log('Verification failed.');
80  })
81  ```
82