js-apis-uripermissionmanager.md 3.0 KB
Newer Older
W
wusongqing 已提交
1
# uriPermissionManager
W
wusongqing 已提交
2

3
> **NOTE**<br>
W
wusongqing 已提交
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.
W
wusongqing 已提交
5 6 7 8 9 10 11 12 13


Implements URI permission management.


## Modules to Import

  
```
W
wusongqing 已提交
14
import uriPermissionManager from '@ohos.application.uriPermissionManager';
W
wusongqing 已提交
15 16 17
```


W
wusongqing 已提交
18
## uriPermissionManager.verifyUriPermission
W
wusongqing 已提交
19 20 21

verifyUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number, callback: AsyncCallback&lt;number&gt;): void

W
wusongqing 已提交
22
Checks whether an application has the permission specified by **flag** for an URI. This API uses a callback to return the result.
W
wusongqing 已提交
23

W
wusongqing 已提交
24
**System capability**:
W
wusongqing 已提交
25 26 27

SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
28 29
**Parameters**

30 31 32 33 34 35
 | Name | Type | Mandatory | Description | 
 | -------- | -------- | -------- | -------- |
 | uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. | 
 | flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. | 
 | accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. | 
 | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. | 
W
wusongqing 已提交
36

W
wusongqing 已提交
37
**Example**
W
wusongqing 已提交
38 39 40 41 42 43 44 45 46
    
  ```
  let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
  UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => {
      console.log("result.code = " + result.code)
  }) // accessTokenId is obtained through the **BundleManager** API.
  ```


W
wusongqing 已提交
47
## uriPermissionManager.verifyUriPermission
W
wusongqing 已提交
48 49 50

verifyUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number): Promise&lt;number&gt;

W
wusongqing 已提交
51
Checks whether an application has the permission specified by **flag** for an URI. This API uses a promise to return the result.
W
wusongqing 已提交
52

W
wusongqing 已提交
53
**System capability**:
W
wusongqing 已提交
54 55 56

SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
57 58
**Parameters**

59 60 61 62 63
 | Name | Type | Mandatory | Description | 
 | -------- | -------- | -------- | -------- |
 | uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. | 
 | flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. | 
 | accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. | 
W
wusongqing 已提交
64

W
wusongqing 已提交
65 66
**Return value**

67 68 69
 | Type | Description | 
 | -------- | -------- |
 | Promise&lt;number&gt; | Promise used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. | 
W
wusongqing 已提交
70

W
wusongqing 已提交
71
**Example**
W
wusongqing 已提交
72 73 74 75 76 77 78 79 80
    
  ```
  let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
  UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId)
  .then((data) => {
      console.log('Verification succeeded.' + data)
  }).catch((error) => {
      console.log('Verification failed.');
  })
81
  ```