提交 ee8ad91d 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 127655ad
...@@ -421,7 +421,6 @@ ...@@ -421,7 +421,6 @@
- Account Management - Account Management
- [@ohos.account.appAccount (App Account Management)](js-apis-appAccount.md) - [@ohos.account.appAccount (App Account Management)](js-apis-appAccount.md)
- [@ohos.account.appAccount.AuthorizationExtensionAbility (App AuthorizationExtensionAbility)](js-apis-appAccount-authorizationExtensionAbility.md)
- [@ohos.account.distributedAccount (Distributed Account Management)](js-apis-distributed-account.md) - [@ohos.account.distributedAccount (Distributed Account Management)](js-apis-distributed-account.md)
- [@ohos.account.osAccount (OS Account Management)](js-apis-osAccount.md) - [@ohos.account.osAccount (OS Account Management)](js-apis-osAccount.md)
......
# @ohos.account.appAccount.AuthorizationExtensionAbility (App AuthorizationExtensionAbility)
The **AuthorizationExtensionAbility** module provides APIs for implementing authorization to app accounts based on the ExtensionAbility framework.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
import AuthorizationExtensionAbility, { AuthorizationRequest, AuthorizationCallback } from '@ohos.account.appAccount.AuthorizationExtensionAbility';
```
## AuthorizationRequest
Defines the app account authorization request.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.AppAccount
| Name | Type | Readable| Writable| Description |
| --------- | ------------------------------- | ---- | ---- | ------------------------------------ |
| callerUid | number | Yes | No | UID of the caller.|
| parameters | [appAccount.AccountCapabilityRequest](js-apis-appAccount.md#accountcapabilityrequest10) | Yes | No | Service parameters.|
## AuthorizationCallback
Provides callbacks to be invoked during the app account authorization.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.AppAccount
| Name | Type | Readable| Writable| Description |
| --------- | ------------------------------- | ---- | ---- | ------------------------------------ |
| onResult | AsyncCallback<[appAccount.AccountCapabilityResponse](js-apis-appAccount.md#accountcapabilityresponse10), { [key: string]: object }> | Yes | No | Callback invoked to return the authorization result.|
## AuthorizationExtensionAbility.onStartAuthorization
onStartAuthorization(request: AuthorizationRequest, callback: AuthorizationCallback): void
Called when an authorization request is received.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.AppAccount
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------------- |
| request | [AuthorizationRequest](#authorizationrequest) | Yes | Authorization request information.|
| callback | [AuthorizationCallback](#authorizationcallback) | Yes | Authorization callback object.|
**Example**
```ts
class MyAuthorizationExtensionAbility extends AuthorizationExtensionAbility {
onStartAuthorization(request: AuthorizationRequest, callback: AuthorizationCallback) {
console.log('onStartAuthorization, callerUid: ' + request.callerUid + ', parameters: ' + request.parameters);
let response = {
name: 'xxxx',
scopes: ['xxx', 'xxx']
};
callback.onResult(null, response);
}
};
```
...@@ -13,7 +13,7 @@ Applications can call the APIs to: ...@@ -13,7 +13,7 @@ Applications can call the APIs to:
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -39,9 +39,9 @@ Creates a **DeviceManager** instance. The **DeviceManager** instance is the entr ...@@ -39,9 +39,9 @@ Creates a **DeviceManager** instance. The **DeviceManager** instance is the entr
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------------------------- | --------- | | ------------------------------------------- | --------- |
| [DeviceManager](#devicemanager) | **DeviceManager** instance created.| | [DeviceManager](#devicemanager) | **DeviceManager** instance created.|
**Example** **Example**
...@@ -97,7 +97,7 @@ Represents the basic information about a distributed device. ...@@ -97,7 +97,7 @@ Represents the basic information about a distributed device.
| ---------------------- | ------------------------- | ---- | -------- | | ---------------------- | ------------------------- | ---- | -------- |
| deviceId | string | Yes | Unique ID of the device. The value is the udid-hash (hash value of the UDID) and appid encrypted using SHA-256.| | deviceId | string | Yes | Unique ID of the device. The value is the udid-hash (hash value of the UDID) and appid encrypted using SHA-256.|
| deviceName | string | Yes | Device name. | | deviceName | string | Yes | Device name. |
| deviceType | number | Yes | Device type. | | deviceType | string | Yes | Device type. |
| networkId | string | No | Network ID of the device. | | networkId | string | No | Network ID of the device. |
## DeviceStateChange ## DeviceStateChange
...@@ -129,9 +129,9 @@ Obtains all trusted devices synchronously. ...@@ -129,9 +129,9 @@ Obtains all trusted devices synchronously.
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------------------------- | --------- | | ------------------------------------------- | --------- |
| Array&lt;[DeviceBasicInfo](#devicebasicinfo)&gt; | List of trusted devices obtained.| | Array&lt;[DeviceBasicInfo](#devicebasicinfo)&gt; | List of trusted devices obtained.|
**Error codes** **Error codes**
...@@ -163,9 +163,9 @@ Obtains all trusted devices. This API uses an asynchronous callback to return th ...@@ -163,9 +163,9 @@ Obtains all trusted devices. This API uses an asynchronous callback to return th
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------- | | -------- | ---------------------------------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Array&lt;[DeviceBasicInfo](#devicebasicinfo)&gt;&gt; | Yes | Callback invoked to return the list of trusted devices.| | callback | AsyncCallback&lt;Array&lt;[DeviceBasicInfo](#devicebasicinfo)&gt;&gt; | Yes | Callback invoked to return the list of trusted devices.|
**Error codes** **Error codes**
...@@ -203,9 +203,9 @@ Obtains all trusted devices. This API uses a promise to return the result. ...@@ -203,9 +203,9 @@ Obtains all trusted devices. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------------------------- | ---------------------------------- | | ---------------------------------------------------------- | ---------------------------------- |
| Promise&lt;Array&lt;[DeviceBasicInfo](#devicebasicinfo)&gt;&gt; | Promise used to return the result.| | Promise&lt;Array&lt;[DeviceBasicInfo](#devicebasicinfo)&gt;&gt; | Promise used to return the result.|
**Error codes** **Error codes**
...@@ -237,9 +237,9 @@ Obtains the network ID of the local device. ...@@ -237,9 +237,9 @@ Obtains the network ID of the local device.
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------- | ---------------- | | ------------------------- | ---------------- |
| string | Network ID of the local device obtained.| | string | Network ID of the local device obtained.|
**Error codes** **Error codes**
...@@ -272,9 +272,9 @@ Obtains the local device name. ...@@ -272,9 +272,9 @@ Obtains the local device name.
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------- | ---------------- | | ------------------------- | ---------------- |
| string | Name of the local device obtained.| | string | Name of the local device obtained.|
**Error codes** **Error codes**
...@@ -307,9 +307,9 @@ Obtains the local device type. ...@@ -307,9 +307,9 @@ Obtains the local device type.
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------- | ---------------- | | ------------------------- | ---------------- |
| number | Local device type obtained.| | number | Local device type obtained.|
**Error codes** **Error codes**
...@@ -342,9 +342,9 @@ Obtains the local device ID. ...@@ -342,9 +342,9 @@ Obtains the local device ID.
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------- | ---------------- | | ------------------------- | ---------------- |
| string | Local device ID obtained.| | string | Local device ID obtained.|
**Error codes** **Error codes**
...@@ -377,15 +377,15 @@ Obtains the device name based on the network ID of the specified device. ...@@ -377,15 +377,15 @@ Obtains the device name based on the network ID of the specified device.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------- | | -------- | ---------------------------------------- | ---- | --------- |
| networkId| string | Yes | Network ID of the device.| | networkId| string | Yes | Network ID of the device.|
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------- | ---------------- | | ------------------------- | ---------------- |
| string | Device name obtained.| | string | Device name obtained.|
**Error codes** **Error codes**
...@@ -420,15 +420,15 @@ Obtains the device type based on the network ID of the specified device. ...@@ -420,15 +420,15 @@ Obtains the device type based on the network ID of the specified device.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------- | | -------- | ---------------------------------------- | ---- | --------- |
| networkId| string | Yes | Network ID of the device.| | networkId| string | Yes | Network ID of the device.|
**Return value** **Return value**
| Name | Description | | Name | Description |
| ------------------------- | ---------------- | | ------------------------- | ---------------- |
| number | Device type obtained.| | number | Device type obtained.|
**Error codes** **Error codes**
...@@ -463,10 +463,10 @@ Starts to discover devices nearby. The discovery process automatically stops whe ...@@ -463,10 +463,10 @@ Starts to discover devices nearby. The discovery process automatically stops whe
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------- | ------------------------------- | ---- | ----- | | ------------- | ------------------------------- | ---- | ----- |
| discoverParam | {[key:&nbsp;string]:&nbsp;Object} | Yes | Identifier of the device to discover. It specifies the type of the target to discover.<br>**discoverTargetType**: The default discovery target is device. The value is **1**.| | discoverParam | {[key:&nbsp;string]:&nbsp;Object} | Yes | Identifier of the device to discover. It specifies the type of the target to discover.<br>**discoverTargetType**: The default discovery target is device. The value is **1**.|
| filterOptions | {[key:&nbsp;string]:&nbsp;Object} | No | Options for filtering discovered devices. The default value is **undefined**, which means to discover offline devices. The following **key** values are carried:<br>**availableStatus(0-1)**: Discover trusted devices only. The value **0** indicates that the device is untrusted.<br>- **0**: The device is offline. The client needs to call **bindTarget** to bind the device.<br>- **1**: The device is online and can be connected.<br>**discoverDistance(0-100)**: Discover devices within a certain distance (in cm) from the local device.<br>**authenticationStatus(0-1)**: Discover devices based on the authentication status.<br>- **0**: The device is not authenticated.<br>- **1**: The device has been authenticated.<br>**authorizationType(0-2)**: Discover devices based on the authorization type.<br>- **0**: device authenticated by a temporarily agreed session key.<br>- **1**: device authenticated by a key of the same account.<br>- **2**: devices authenticated by a credential key of different accounts.| | filterOptions | {[key:&nbsp;string]:&nbsp;Object} | No | Options for filtering discovered devices. The default value is **undefined**, which means to discover offline devices. The following **key** values are carried:<br>**availableStatus(0-1)**: Discover trusted devices only. The value **0** indicates that the device is untrusted.<br>- **0**: The device is offline. The client needs to call **bindTarget** to bind the device.<br>- **1**: The device is online and can be connected.<br>**discoverDistance(0-100)**: Discover devices within a certain distance (in cm) from the local device.<br>**authenticationStatus(0-1)**: Discover devices based on the authentication status.<br>- **0**: The device is not authenticated.<br>- **1**: The device has been authenticated.<br>**authorizationType(0-2)**: Discover devices based on the authorization type.<br>- **0**: device authenticated by a temporarily agreed session key.<br>- **1**: device authenticated by a key of the same account.<br>- **2**: devices authenticated by a credential key of different accounts.|
**Error codes** **Error codes**
...@@ -537,11 +537,11 @@ Binds a device. ...@@ -537,11 +537,11 @@ Binds a device.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | --------------------------------------------------- | ----- | ------------ | | ---------- | --------------------------------------------------- | ----- | ------------ |
| deviceId | string | Yes | Device ID. | | deviceId | string | Yes | Device ID. |
| bindParam | {[key:&nbsp;string]:&nbsp;Object} | Yes | Authentication parameters. You can determine the key-value pair to be passed in. By default, the following **key** values are carried:<br>**bindType**: binding type.<br>- **1**: PIN.<br>- **2**: QR code.<br>- 3: NFC.<br>- 4: No interaction.<br>**targetPkgName**: bundle name of the target to bind.<br>**appName**: application that attempts to bind the target.<br>**appOperation**: reason for the application to bind the target.<br>**customDescription**: detailed description of the operation. | | bindParam | {[key:&nbsp;string]:&nbsp;Object} | Yes | Authentication parameters. You can determine the key-value pair to be passed in. By default, the following **key** values are carried:<br>**bindType**: binding type.<br>- **1**: PIN.<br>- **2**: QR code.<br>- 3: NFC.<br>- 4: No interaction.<br>**targetPkgName**: bundle name of the target to bind.<br>**appName**: application that attempts to bind the target.<br>**appOperation**: reason for the application to bind the target.<br>**customDescription**: detailed description of the operation. |
| callback | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;}&gt; | Yes | Callback invoked to return the authentication result.| | callback | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;}&gt; | Yes | Callback invoked to return the authentication result.|
**Error codes** **Error codes**
...@@ -589,9 +589,9 @@ Unbinds a device. ...@@ -589,9 +589,9 @@ Unbinds a device.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- | | -------- | ------------------------- | ---- | ---------- |
| deviceId | string | Yes | Device ID.| | deviceId | string | Yes | Device ID.|
**Error codes** **Error codes**
...@@ -626,10 +626,10 @@ Replies to the user's UI operation. This API can be used only by the PIN HAP of ...@@ -626,10 +626,10 @@ Replies to the user's UI operation. This API can be used only by the PIN HAP of
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------- | --------------- | ---- | ------------------- | | ------------- | --------------- | ---- | ------------------- |
| action | number | Yes | User operation. | | action | number | Yes | User operation. |
| actionResult | string | Yes | Operation result.| | actionResult | string | Yes | Operation result.|
**Example** **Example**
...@@ -664,10 +664,10 @@ Subscribes to the UI operation reply result. ...@@ -664,10 +664,10 @@ Subscribes to the UI operation reply result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------ | | -------- | ------------------------------------ | ---- | ------------------------------ |
| type | string | Yes | Event type to subscribe to. The value **replyResult** indicates the reply result of the UI operation.| | type | string | Yes | Event type to subscribe to. The value **replyResult** indicates the reply result of the UI operation.|
| callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | Yes | Callback invoked to return the UI status. | | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | Yes | Callback invoked to return the UI status. |
**Example** **Example**
...@@ -698,10 +698,10 @@ Unsubscribes from the UI operation reply result. ...@@ -698,10 +698,10 @@ Unsubscribes from the UI operation reply result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ------------------------------ | | -------- | ------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type to unsubscribe from. The value **replyResult** indicates the reply result of the UI operation.| | type | string | Yes | Event type to unsubscribe from. The value **replyResult** indicates the reply result of the UI operation.|
| callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | No | Callback for the UI status.| | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | No | Callback for the UI status.|
**Example** **Example**
...@@ -725,10 +725,10 @@ Subscribes to changes in the device state. ...@@ -725,10 +725,10 @@ Subscribes to changes in the device state.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event.| | type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event.|
| callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChange](#devicestatechange),&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | Yes | Callback invoked to return the device information and state. | | callback | Callback&lt;{&nbsp;action:&nbsp;[DeviceStateChange](#devicestatechange),&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | Yes | Callback invoked to return the device information and state. |
**Example** **Example**
...@@ -754,10 +754,10 @@ Unsubscribes from changes in the device state. ...@@ -754,10 +754,10 @@ Unsubscribes from changes in the device state.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | ---------------------------------------- | ---- | --------------------------- |
| type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event. | | type | string | Yes | Event type. The value **'deviceStateChange'** indicates a device state change event. |
| callback | Callback&lt;{&nbsp;action:&nbsp;[deviceStateChange](#devicestatechange),&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | No | Callback for the device information and state.| | callback | Callback&lt;{&nbsp;action:&nbsp;[deviceStateChange](#devicestatechange),&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | No | Callback for the device information and state.|
**Example** **Example**
...@@ -783,10 +783,10 @@ Subscribes to device discovery events. ...@@ -783,10 +783,10 @@ Subscribes to device discovery events.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------- | | -------- | ---------------------------------------- | ---- | -------------------------- |
| type | string | Yes | Event type. The value **'discoverSuccess'** indicates an event of successful device discovery.| | type | string | Yes | Event type. The value **'discoverSuccess'** indicates an event of successful device discovery.|
| callback | Callback&lt;{&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | Yes | Callback invoked to return a device discovery event. | | callback | Callback&lt;{&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | Yes | Callback invoked to return a device discovery event. |
**Example** **Example**
...@@ -812,10 +812,10 @@ Unsubscribes from device discovery events. ...@@ -812,10 +812,10 @@ Unsubscribes from device discovery events.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | ---------------------------------------- | ---- | --------------------------- |
| type | string | Yes | Event type. The value **'discoverSuccess'** indicates a device discovery event. | | type | string | Yes | Event type. The value **'discoverSuccess'** indicates a device discovery event. |
| callback | Callback&lt;{&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | No | Callback for the device discovery event.| | callback | Callback&lt;{&nbsp;device:&nbsp;[DeviceBasicInfo](#devicebasicinfo)&nbsp;}&gt; | No | Callback for the device discovery event.|
**Example** **Example**
...@@ -841,10 +841,10 @@ Subscribes to device name changes. ...@@ -841,10 +841,10 @@ Subscribes to device name changes.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value **'deviceNameChange'** indicates a device name change event.| | type | string | Yes | Event type. The value **'deviceNameChange'** indicates a device name change event.|
| callback | Callback&lt;{&nbsp;deviceName:&nbsp;string}&gt; | Yes | Callback invoked to return the device name change. | | callback | Callback&lt;{&nbsp;deviceName:&nbsp;string}&gt; | Yes | Callback invoked to return the device name change. |
**Example** **Example**
...@@ -870,10 +870,10 @@ Unsubscribes from device name changes. ...@@ -870,10 +870,10 @@ Unsubscribes from device name changes.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value **'deviceNameChange'** indicates a device name change event.| | type | string | Yes | Event type. The value **'deviceNameChange'** indicates a device name change event.|
| callback | Callback&lt;{&nbsp;deviceName:&nbsp;string}&gt; | No | Callback for the device name change. | | callback | Callback&lt;{&nbsp;deviceName:&nbsp;string}&gt; | No | Callback for the device name change. |
**Example** **Example**
...@@ -899,10 +899,10 @@ Subscribes to device discovery failures. ...@@ -899,10 +899,10 @@ Subscribes to device discovery failures.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value **'discoverFailure'** indicates an event reported when device discovery fails.| | type | string | Yes | Event type. The value **'discoverFailure'** indicates an event reported when device discovery fails.|
| callback | Callback&lt;{&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes | Callback invoked to return a device discovery failure. | | callback | Callback&lt;{&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes | Callback invoked to return a device discovery failure. |
**Example** **Example**
...@@ -928,10 +928,10 @@ Unsubscribes from device discovery failures. ...@@ -928,10 +928,10 @@ Unsubscribes from device discovery failures.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------- | | -------- | ---------------------------------------- | ---- | ----------------- |
| type | string | Yes | Event type. The value **'discoverFailure'** indicates an event reported when device discovery fails. | | type | string | Yes | Event type. The value **'discoverFailure'** indicates an event reported when device discovery fails. |
| callback | Callback&lt;{&nbsp;reason:&nbsp;number&nbsp;}&gt; | No | Callback for the device discovery failure.| | callback | Callback&lt;{&nbsp;reason:&nbsp;number&nbsp;}&gt; | No | Callback for the device discovery failure.|
**Example** **Example**
...@@ -957,10 +957,10 @@ Subscribes to dead events of the **DeviceManager** service. ...@@ -957,10 +957,10 @@ Subscribes to dead events of the **DeviceManager** service.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ----------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.| | type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | Callback&lt;{}&gt; | No | Callback invoked when a dead event of the **DeviceManager** service occurs. | | callback | Callback&lt;{}&gt; | No | Callback invoked when a dead event of the **DeviceManager** service occurs. |
**Example** **Example**
...@@ -986,10 +986,10 @@ Unsubscribes from dead events of the **DeviceManager** service. ...@@ -986,10 +986,10 @@ Unsubscribes from dead events of the **DeviceManager** service.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ----------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.| | type | string | Yes | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
| callback | Callback&lt;{}&gt; | No | Callback for the dead event of the **DeviceManager** service. | | callback | Callback&lt;{}&gt; | No | Callback for the dead event of the **DeviceManager** service. |
**Example** **Example**
...@@ -1002,4 +1002,4 @@ Unsubscribes from dead events of the **DeviceManager** service. ...@@ -1002,4 +1002,4 @@ Unsubscribes from dead events of the **DeviceManager** service.
console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message); console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
} }
``` ```
...@@ -2687,7 +2687,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c ...@@ -2687,7 +2687,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| ------ | ------ | ---- | ---- | ---------------------------------------- | | ------ | ------ | ---- | ---- | ---------------------------------------- |
| ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| | | ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| |
| mode | number | Yes | No | File permissions. The meaning of each bit is as follows:<br>- **0o400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or read a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| | mode | number | Yes | No | File permissions. The meaning of each bit is as follows:<br>**NOTE**<br>The following values are in octal format. The returned values are in decimal format. You need to convert the values.<br>- **0o400**: The owner has the permission to read a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the permission to read a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| uid | number | Yes | No | ID of the file owner.| | uid | number | Yes | No | ID of the file owner.|
| gid | number | Yes | No | ID of the user group of the file.| | gid | number | Yes | No | ID of the user group of the file.|
| size | number | Yes | No | File size, in bytes. This parameter is valid only for regular files. | | size | number | Yes | No | File size, in bytes. This parameter is valid only for regular files. |
......
# @ohos.file.fileAccess (User File Access and Management) # @ohos.file.fileAccess (User File Access and Management)
The **fileAccess** module provides a framework for accessing and operating user files based on the ExtensionAbility mechanism. This module interacts with file management services, such as the media library and external storage management service, and provides a set of unified interfaces for system applications to access and manage files. The media library service allows access to user files on local and distributed devices. The external storage management service allows access to the user files stored on devices, such as shared disks, USB flash drives, and SD cards. The **fileAccess** module provides a framework for accessing and operating user files based on the ExtensionAbility mechanism. This module interacts with a variety of file management services, such as the storage management service, and provides a set of unified file access and management interfaces for system applications. The storage management service manages both the directories of the built-in storage and resources on external devices, such as shared disks, USB flash drives, and SD cards.
>**NOTE** >**NOTE**
> >
...@@ -124,10 +124,9 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -124,10 +124,9 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
createFileAccessHelper() { createFileAccessHelper() {
let fileAccessHelper = null; let fileAccessHelper = null;
// Obtain wantInfos by using getFileAccessAbilityInfo(). // Obtain wantInfos by using getFileAccessAbilityInfo().
// Create a helper object to interact with the media library service only.
let wantInfos = [ let wantInfos = [
{ {
"bundleName": "com.ohos.medialibrary.medialibrarydata", "bundleName": "com.ohos.UserFile.ExternalFileManager",
"abilityName": "FileExtensionAbility", "abilityName": "FileExtensionAbility",
}, },
] ]
...@@ -248,7 +247,7 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -248,7 +247,7 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
try { try {
let fileIterator = fileInfoDir.listFile(); let fileIterator = fileInfoDir.listFile();
// listFile() with the filter implementation. // listFile() with the filter implementation.
// let fileIterator = rootInfo.listFile(filter); // let fileIterator = fileInfoDir.listFile(filter);
if (!fileIterator) { if (!fileIterator) {
console.error("listFile interface returns an undefined object"); console.error("listFile interface returns an undefined object");
return; return;
...@@ -304,7 +303,7 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -304,7 +303,7 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
try { try {
let fileIterator = fileInfoDir.scanFile(); let fileIterator = fileInfoDir.scanFile();
// scanFile() with the filter implementation. // scanFile() with the filter implementation.
// let fileIterator = rootInfo.scanFile(filter); // let fileIterator = fileInfoDir.scanFile(filter);
if (!fileIterator) { if (!fileIterator) {
console.error("scanFile interface returns an undefined object"); console.error("scanFile interface returns an undefined object");
return; return;
...@@ -651,10 +650,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -651,10 +650,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceUri = "file://media/file/6"; let sourceUri = "file://docs/storage/Users/currentUser/Download";
let displayName = "file1" let displayName = "file1"
let fileUri = null; let fileUri = null;
try { try {
...@@ -695,10 +694,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -695,10 +694,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceUri = "file://media/file/6"; let sourceUri = "file://docs/storage/Users/currentUser/Download";
let displayName = "file1" let displayName = "file1"
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
...@@ -744,10 +743,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -744,10 +743,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceUri = "file://media/file/6"; let sourceUri = "file://docs/storage/Users/currentUser/Download";
let dirName = "dirTest" let dirName = "dirTest"
let dirUri = null; let dirUri = null;
try { try {
...@@ -788,10 +787,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -788,10 +787,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceUri = "file://media/file/6"; let sourceUri = "file://docs/storage/Users/currentUser/Download";
let dirName = "dirTest" let dirName = "dirTest"
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
...@@ -837,10 +836,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -837,10 +836,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let targetUri = "file://media/file/100"; let targetUri = "file://docs/storage/Users/currentUser/Download/1.txt";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let fd = await fileAccessHelper.openFile(targetUri, fileAccess.OPENFLAGS.READ); let fd = await fileAccessHelper.openFile(targetUri, fileAccess.OPENFLAGS.READ);
...@@ -874,10 +873,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -874,10 +873,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let targetUri = "file://media/file/100"; let targetUri = "file://docs/storage/Users/currentUser/Download/1.txt";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.openFile(targetUri, fileAccess.OPENFLAGS.READ, function (err, fd) { fileAccessHelper.openFile(targetUri, fileAccess.OPENFLAGS.READ, function (err, fd) {
...@@ -921,10 +920,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -921,10 +920,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let targetUri = "file://media/file/100"; let targetUri = "file://docs/storage/Users/currentUser/Download/1.txt";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let code = await fileAccessHelper.delete(targetUri); let code = await fileAccessHelper.delete(targetUri);
...@@ -959,10 +958,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -959,10 +958,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, targetUri indicates a file in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let targetUri = "file://media/file/100"; let targetUri = "file://docs/storage/Users/currentUser/Download/1.txt";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.delete(targetUri, function (err, code) { fileAccessHelper.delete(targetUri, function (err, code) {
...@@ -1007,11 +1006,11 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -1007,11 +1006,11 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceFile and destFile indicate the files or directories in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceFile = "file://media/file/102"; let sourceFile = "file://docs/storage/Users/currentUser/Download/1.txt";
let destFile = "file://media/file/101"; let destFile = "file://docs/storage/Users/currentUser/Download/test";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let fileUri = await fileAccessHelper.move(sourceFile, destFile); let fileUri = await fileAccessHelper.move(sourceFile, destFile);
...@@ -1046,11 +1045,11 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -1046,11 +1045,11 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceFile and destFile indicate the files or directories in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceFile = "file://media/file/102"; let sourceFile = "file://docs/storage/Users/currentUser/Download/1.txt";
let destFile = "file://media/file/101"; let destFile = "file://docs/storage/Users/currentUser/Download/test";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.move(sourceFile, destFile, function (err, fileUri) { fileAccessHelper.move(sourceFile, destFile, function (err, fileUri) {
...@@ -1095,10 +1094,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -1095,10 +1094,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceDir indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceDir indicates a file in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceDir = "file://media/file/100"; let sourceDir = "file://docs/storage/Users/currentUser/Download/1.txt";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let DestDir = await fileAccessHelper.rename(sourceDir, "testDir"); let DestDir = await fileAccessHelper.rename(sourceDir, "testDir");
...@@ -1133,10 +1132,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -1133,10 +1132,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceDir indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceDir indicates a file in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceDir = "file://media/file/100"; let sourceDir = "file://docs/storage/Users/currentUser/Download/1.txt";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.rename(sourceDir, "testDir", function (err, DestDir) { fileAccessHelper.rename(sourceDir, "testDir", function (err, DestDir) {
...@@ -1180,10 +1179,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -1180,10 +1179,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceDir indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceDir indicates a file in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceDir = "file://media/file/100"; let sourceDir = "file://docs/storage/Users/currentUser/Download/1.txt";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let existJudgment = await fileAccessHelper.access(sourceDir); let existJudgment = await fileAccessHelper.access(sourceDir);
...@@ -1220,10 +1219,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e ...@@ -1220,10 +1219,10 @@ For details about error codes, see [File Management Error Codes](../errorcodes/e
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceDir indicates a file in the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceDir indicates a folder in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceDir = "file://media/file/100"; let sourceDir = "file://docs/storage/Users/currentUser/Download/test";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.access(sourceDir, function (err, existJudgment) { fileAccessHelper.access(sourceDir, function (err, existJudgment) {
...@@ -1266,10 +1265,10 @@ Obtains a **FileInfo** object based on the specified URI. This API uses a promis ...@@ -1266,10 +1265,10 @@ Obtains a **FileInfo** object based on the specified URI. This API uses a promis
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceUri = "file://media/file/6"; let sourceUri = "file://docs/storage/Users/currentUser/Download";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let fileInfo = await fileAccessHelper.getFileInfoFromUri(sourceUri); let fileInfo = await fileAccessHelper.getFileInfoFromUri(sourceUri);
...@@ -1298,10 +1297,10 @@ Obtains a **FileInfo** object based on the specified URI. This API uses an async ...@@ -1298,10 +1297,10 @@ Obtains a **FileInfo** object based on the specified URI. This API uses an async
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo. // In the sample code, sourceUri indicates the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceUri = "file://media/file/6"; let sourceUri = "file://docs/storage/Users/currentUser/Download";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.getFileInfoFromUri(sourceUri, function (err, fileInfo) { fileAccessHelper.getFileInfoFromUri(sourceUri, function (err, fileInfo) {
...@@ -1342,7 +1341,6 @@ Obtains a **FileInfo** object based on the **relativePath**. This API uses a pro ...@@ -1342,7 +1341,6 @@ Obtains a **FileInfo** object based on the **relativePath**. This API uses a pro
**Example** **Example**
```js ```js
// The relative path of the Media Library is used as an example.
// In the sample code, relativePath indicates the Download directory, which is the relativePath in fileInfo. // In the sample code, relativePath indicates the Download directory, which is the relativePath in fileInfo.
// You can use the relativePath obtained. // You can use the relativePath obtained.
let relativePath = "Download/"; let relativePath = "Download/";
...@@ -1374,7 +1372,6 @@ Obtains a **FileInfo** object based on the **relativePath**. This API uses an as ...@@ -1374,7 +1372,6 @@ Obtains a **FileInfo** object based on the **relativePath**. This API uses an as
**Example** **Example**
```js ```js
// The relative path of the Media Library is used as an example.
// In the sample code, relativePath indicates the Download directory, which is the relativePath in fileInfo. // In the sample code, relativePath indicates the Download directory, which is the relativePath in fileInfo.
// You can use the relativePath obtained. // You can use the relativePath obtained.
let relativePath = "Download/"; let relativePath = "Download/";
...@@ -1392,90 +1389,6 @@ Obtains a **FileInfo** object based on the **relativePath**. This API uses an as ...@@ -1392,90 +1389,6 @@ Obtains a **FileInfo** object based on the **relativePath**. This API uses an as
}; };
``` ```
### getThumbnail<sup>10+</sup>
getThumbnail(uri: string, size: image.Size) : Promise&lt;image.PixelMap&gt;
Obtains the **Pixelmap** object of a media file based on the specified URI and size. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------------- | ---- | ----------- |
| uri | string | Yes | URI of the media file.|
| size | [image.Size](js-apis-image.md#size) | Yes | Size of the thumbnail. |
**Return value**
| Type | Description |
| :---------------------------- | :----------------- |
| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Promise used to return the **Pixelmap** object obtained.|
**Example**
```js
// The media library URI is used as an example.
// In the sample code, targetUri indicates a media file (image, audio, or video) in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let targetUri = "file://media/image/100";
let size = { width: 128, height: 128 };
try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let pixelMap = await fileAccessHelper.getThumbnail(targetUri, size);
let imageInfo = await pixelMap.getImageInfo();
console.log("getThumbnail sucess, pixelMap.width: " + imageInfo.size.width);
console.log("getThumbnail sucess, pixelMap.height: " + imageInfo.size.height);
} catch (error) {
console.error("getThumbnail failed, errCode:" + error.code + ", errMessage:" + error.message);
};
```
### getThumbnail<sup>10+</sup>
getThumbnail(uri: string, size: image.Size, callback: AsyncCallback&lt;image.PixelMap&gt;) : void
Obtains the **Pixelmap** object of a media file based on the specified URI and size. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------ |
| uri | string | Yes | URI of the media file. |
| size | [image.Size](js-apis-image.md#size) | Yes | Size of the thumbnail. |
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes | Callback invoked to return the **Pixelmap** object obtained.|
**Example**
```js
// The media library URI is used as an example.
// In the sample code, targetUri indicates a media file (image, audio, or video) in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let targetUri = "file://media/image/100";
let size = { width: 128, height: 128 };
try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.getThumbnail(targetUri, size, async(err, pixelMap) => {
if (err) {
console.error("Failed to getThumbnail in async, errCode:" + err.code + ", errMessage:" + err.message);
return;
}
let imageInfo = await pixelMap.getImageInfo();
console.log("getThumbnail sucess, pixelMap.width: " + imageInfo.size.width);
console.log("getThumbnail sucess, pixelMap.height: " + imageInfo.size.height);
});
} catch (error) {
console.error("getThumbnail failed, errCode:" + error.code + ", errMessage:" + error.message);
};
```
### query<sup>10+</sup> ### query<sup>10+</sup>
query(uri:string, metaJson: string) : Promise&lt;string&gt; query(uri:string, metaJson: string) : Promise&lt;string&gt;
...@@ -1502,7 +1415,7 @@ Queries the attribute information about a file or directory based on the URI. Th ...@@ -1502,7 +1415,7 @@ Queries the attribute information about a file or directory based on the URI. Th
**Example** **Example**
```js ```js
var imageFileRelativePath = "Download/queryTest/image/01.jpg"; var imageFileRelativePath = "/storage/Users/currentUser/Download/queryTest/image/01.jpg";
var jsonStrSingleRelativepath = JSON.stringify({ [fileAccess.FileKey.RELATIVE_PATH]: "" }); var jsonStrSingleRelativepath = JSON.stringify({ [fileAccess.FileKey.RELATIVE_PATH]: "" });
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
...@@ -1535,7 +1448,7 @@ Queries the attribute information about a file or directory based on the URI. Th ...@@ -1535,7 +1448,7 @@ Queries the attribute information about a file or directory based on the URI. Th
**Example** **Example**
```js ```js
var imageFileRelativePath = "Download/queryTest/image/01.jpg"; var imageFileRelativePath = "/storage/Users/currentUser/Download/queryTest/image/01.jpg";
var jsonStrSingleRelativepath = JSON.stringify({ [fileAccess.FileKey.RELATIVE_PATH]: "" }); var jsonStrSingleRelativepath = JSON.stringify({ [fileAccess.FileKey.RELATIVE_PATH]: "" });
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
...@@ -1566,8 +1479,8 @@ Copies a file or directory. This API uses a promise to return the result. ...@@ -1566,8 +1479,8 @@ Copies a file or directory. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------- | ---- | ------------------------------------------------------------ | | --------- | ------- | ---- | ------------------------------------------------------------ |
| sourceUri | string | Yes | URI of the file or directory to copy, for example, **file://media/file/102**. | | sourceUri | string | Yes | URI of the file or folder to copy, for example, **file://docs/storage/Users/currentUser/Download/1.txt**. |
| destUri | string | Yes | URI of the destination directory, for example, **file://media/file/101**. | | destUri | string | Yes | URI of the file or folder created, for example, **file://docs/storage/Users/currentUser/Download/test**. |
| force | boolean | No | Whether to forcibly overwrite the file with the same name. <br>If **force** is **true**, the file with the same name will be overwritten. If **force** is **false** or not specified, the file with the same name will not be overwritten.| | force | boolean | No | Whether to forcibly overwrite the file with the same name. <br>If **force** is **true**, the file with the same name will be overwritten. If **force** is **false** or not specified, the file with the same name will not be overwritten.|
**Return value** **Return value**
...@@ -1579,11 +1492,11 @@ Copies a file or directory. This API uses a promise to return the result. ...@@ -1579,11 +1492,11 @@ Copies a file or directory. This API uses a promise to return the result.
Example 1: Copy a file with **force** unspecified. Example 1: Copy a file with **force** unspecified.
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo. // In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceFile = "file://media/file/102"; let sourceFile = "file://docs/storage/Users/currentUser/Download/1.txt";
let destFile = "file://media/file/101"; let destFile = "file://docs/storage/Users/currentUser/Download/test";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let copyResult = await fileAccessHelper.copy(sourceFile, destFile); let copyResult = await fileAccessHelper.copy(sourceFile, destFile);
...@@ -1605,11 +1518,11 @@ try { ...@@ -1605,11 +1518,11 @@ try {
Example 2: Copy a file or directory when **force** set to **true**. Example 2: Copy a file or directory when **force** set to **true**.
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo. // In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceFile = "file://media/file/102"; let sourceFile = "file://docs/storage/Users/currentUser/Download/1.txt";
let destFile = "file://media/file/101"; let destFile = "file://docs/storage/Users/currentUser/Download/test";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
let copyResult = await fileAccessHelper.copy(sourceFile, destFile, true); let copyResult = await fileAccessHelper.copy(sourceFile, destFile, true);
...@@ -1642,18 +1555,18 @@ Copies a file or directory. This API uses an asynchronous callback to return the ...@@ -1642,18 +1555,18 @@ Copies a file or directory. This API uses an asynchronous callback to return the
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | --------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| sourceUri | string | Yes | URI of the file or directory to copy, for example, **file://media/file/102**. | | sourceUri | string | Yes | URI of the file or folder to copy, for example, **file://docs/storage/Users/currentUser/Download/1.txt**. |
| destUri | string | Yes | URI of the destination directory, for example, **file://media/file/101**. | | destUri | string | Yes | URI of the file or folder created, for example, **file://docs/storage/Users/currentUser/Download/test**. |
| callback | AsyncCallback&lt;Array&lt;[CopyResult](#copyresult10)&gt;&gt; | Yes | Callback invoked to return the result. If the file or directory is copied successfully, no information is returned. If the file copy fails, **copyResult** is returned.| | callback | AsyncCallback&lt;Array&lt;[CopyResult](#copyresult10)&gt;&gt; | Yes | Callback invoked to return the result. If the file or directory is copied successfully, no information is returned. If the file copy fails, **copyResult** is returned.|
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo. // In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceFile = "file://media/file/102"; let sourceFile = "file://docs/storage/Users/currentUser/Download/1.txt";
let destFile = "file://media/file/101"; let destFile = "file://docs/storage/Users/currentUser/Download/test";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.copy(sourceFile, destFile, async (err, copyResult) => { fileAccessHelper.copy(sourceFile, destFile, async (err, copyResult) => {
...@@ -1691,19 +1604,19 @@ Copies a file or directory. This API uses an asynchronous callback to return the ...@@ -1691,19 +1604,19 @@ Copies a file or directory. This API uses an asynchronous callback to return the
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | --------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| sourceUri | string | Yes | URI of the file or directory to copy, for example, **file://media/file/102**. | | sourceUri | string | Yes | URI of the file or folder to copy, for example, **file://docs/storage/Users/currentUser/Download/1.txt**. |
| destUri | string | Yes | URI of the destination directory, for example, **file://media/file/101**. | | destUri | string | Yes | URI of the file or folder created, for example, **file://docs/storage/Users/currentUser/Download/test**. |
| force | boolean | Yes | Whether to forcibly overwrite the file with the same name. <br>If **force** is **true**, the file with the same name will be overwritten. If **force** is **false** or not specified, the file with the same name will not be overwritten.| | force | boolean | Yes | Whether to forcibly overwrite the file with the same name. <br>If **force** is **true**, the file with the same name will be overwritten. If **force** is **false** or not specified, the file with the same name will not be overwritten.|
| callback | AsyncCallback&lt;Array&lt;[CopyResult](#copyresult10)&gt;&gt; | Yes | Callback invoked to return the result. If the file or directory is copied successfully, no information is returned. If the file copy fails, **copyResult** is returned.| | callback | AsyncCallback&lt;Array&lt;[CopyResult](#copyresult10)&gt;&gt; | Yes | Callback invoked to return the result. If the file or directory is copied successfully, no information is returned. If the file copy fails, **copyResult** is returned.|
**Example** **Example**
```js ```js
// The media library URI is used as an example. // A built-in storage directory is used as an example.
// In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo. // In the sample code, sourceFile indicates the file (directory) in the Download directory to copy, destFile indicates the destination directory in the Download directory, and uri is to URI in fileInfo.
// You can use the URI obtained. // You can use the URI obtained.
let sourceFile = "file://media/file/102"; let sourceFile = "file://docs/storage/Users/currentUser/Download/1.txt";
let destFile = "file://media/file/101"; let destFile = "file://docs/storage/Users/currentUser/Download/test";
try { try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper. // Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.copy(sourceFile, destFile, true, async (err, copyResult) => { fileAccessHelper.copy(sourceFile, destFile, true, async (err, copyResult) => {
...@@ -1771,6 +1684,3 @@ Enumerates the keys of the file attributes to query. ...@@ -1771,6 +1684,3 @@ Enumerates the keys of the file attributes to query.
| DATE_MODIFIED | 'date_modified' | Date when a file was modified, for example, **1665310670**. | | DATE_MODIFIED | 'date_modified' | Date when a file was modified, for example, **1665310670**. |
| RELATIVE_PATH | 'relative_path' | Relative path of the file, for example, **Pictures/Screenshots/**.| | RELATIVE_PATH | 'relative_path' | Relative path of the file, for example, **Pictures/Screenshots/**.|
| FILE_SIZE | 'size' | Size of a file, in bytes. | | FILE_SIZE | 'size' | Size of a file, in bytes. |
| WIDTH | 'width' | Width of the image file, in pixels. |
| HEIGHT | 'height' | Height of the image file, in pixels. |
| DURATION | 'duration' | Duration of the audio or video file, in milliseconds. |
...@@ -23,20 +23,18 @@ Before developing applications related to tag read and write, you must declare N ...@@ -23,20 +23,18 @@ Before developing applications related to tag read and write, you must declare N
// Add the nfc tag action. // Add the nfc tag action.
"ohos.nfc.tag.action.TAG_FOUND" "ohos.nfc.tag.action.TAG_FOUND"
],
"uris": [
{
"type":"tag-tech/NfcA"
},
{
"type":"tag-tech/IsoDep"
}
// Add other technology if neccessary,
// such as NfcB, NfcF, NfcV, Ndef, MifareClassic, MifareUL, and NdefFormatable.
] ]
} }
],
"metadata": [
{
"name": "tag-tech",
"value": "NfcA"
},
{
"name": "tag-tech",
"value": "IsoDep"
}
// Add other technologies,
// such as NfcB, NfcF, NfcV, Ndef, MifareClassic, MifareUL, and NdefFormatable.
] ]
} }
], ],
...@@ -49,13 +47,11 @@ Before developing applications related to tag read and write, you must declare N ...@@ -49,13 +47,11 @@ Before developing applications related to tag read and write, you must declare N
} }
} }
``` ```
> **CAUTION**<br> > **CAUTION**
> >
> - The **actions** field is mandatory. It must be **ohos.nfc.tag.action.TAG_FOUND** and cannot be changed. > - The **actions** field is mandatory. It must be **ohos.nfc.tag.action.TAG_FOUND** and cannot be changed.
> - The **name** field under **metadata** is mandatory. It must be **tag-tech** and cannot be changed. > - The **type** field under **uris** must start with **tag-tech/**, followed by NfcA, NfcB, NfcF, NfcV, IsoDep, Ndef, MifareClassic, MifareUL, or NdefFormatable. If there are multiple types, enter them in different lines. Incorrect settings of this field will cause a parsing failure.
> - The **value** field under **metadata** is mandatory. It can be **NfcA**, **NfcB**, **NfcF**, **NfcV**, **IsoDep**, **Ndef**, **MifareClassic**, **MifareUL**, **NdefFormatable** or any of their combinations. Incorrect settings of this field will cause a parsing failure.
> - The **name** field under **requestPermissions** is mandatory. It must be **ohos.permission.NFC_TAG** and cannot be changed. > - The **name** field under **requestPermissions** is mandatory. It must be **ohos.permission.NFC_TAG** and cannot be changed.
## **Modules to Import** ## **Modules to Import**
```js ```js
...@@ -528,8 +524,16 @@ import tag from '@ohos.nfc.tag'; ...@@ -528,8 +524,16 @@ import tag from '@ohos.nfc.tag';
let elementName = null; let elementName = null;
let discTech = [tag.NFC_A, tag.NFC_B]; // replace with the tech(s) that is needed by foreground ability let discTech = [tag.NFC_A, tag.NFC_B]; // replace with the tech(s) that is needed by foreground ability
function foregroundCb(tagInfo: any) {
console.log("foreground callback: tag found tagInfo = ", JSON.stringify(tagInfo)); function foregroundCb(err, taginfo) {
if (!err) {
console.log("foreground callback: tag found tagInfo = ", JSON.stringify(tagInfo));
} else {
console.log("foreground callback err: " + err.message);
return;
}
// other Operations of taginfo
} }
export default class MainAbility extends UIAbility { export default class MainAbility extends UIAbility {
...@@ -885,7 +889,7 @@ Enumerates the tag technology types. ...@@ -885,7 +889,7 @@ Enumerates the tag technology types.
| **Name** | **Value**| **Description** | | **Name** | **Value**| **Description** |
| ---------------------------- | ------ | --------------------------- | | ---------------------------- | ------ | --------------------------- |
| NFC_A | 1 | NFC-A (ISO 14443-3A). | | NFC_A | 1 | NFC-A (ISO 14443-3A). |
| NFC_B | 2 | NFC-B (ISO 14443-3B).| | NFC_B | 2 | NFC-B (ISO 14443-3B). |
| ISO_DEP | 3 | ISO-DEP (ISO 14443-4).| | ISO_DEP | 3 | ISO-DEP (ISO 14443-4).|
| NFC_F | 4 | NFC-F (JIS 6319-4). | | NFC_F | 4 | NFC-F (JIS 6319-4). |
| NFC_V | 5 | NFC-V (ISO 15693). | | NFC_V | 5 | NFC-V (ISO 15693). |
......
...@@ -1275,6 +1275,151 @@ async function example() { ...@@ -1275,6 +1275,151 @@ async function example() {
} }
``` ```
### getPhotoIndex
getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback&lt;number&gt;): void
Obtains the index of an image or video in an album. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoUri | string | Yes | URI of the media asset whose index is to be obtained.|
| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. |
| options | [FetchOptions](#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search conditions or sorting modes are set, the API cannot be called successfully. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| AsyncCallback&lt;number&gt;| Promise used to return the index obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 401 | if parameter is invalid. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoIndexDemo');
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
let fetchOp = {
fetchColumns: [],
predicates: predicatesForGetAsset
};
//Obtain the uri of the album
let albumFetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified");
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let photoFetchResult = await album.getAssets(fetchOptions);
let expectIndex = 1;
//Obtain the uri of the second file
let photoAsset = await photoFetchResult.getObjectByPosition(expectIndex);
photoAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => {
try {
if (err == undefined) {
console.info(`getPhotoIndex successfully and index is : ${index}`);
} else {
console.info(`getPhotoIndex failed;`);
}
} catch (error) {
console.info(`getPhotoIndex failed; error: ${error}`);
}
}
}
```
### getPhotoIndex
getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise&lt;number&gt;
Obtains the index of an image or video in an album. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoUri | string | Yes | URI of the media asset whose index is to be obtained.|
| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. |
| options | [FetchOptions](#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search conditions or sorting modes are set, the API cannot be called successfully. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise&lt;number&gt;| Promise used to return the index obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 401 | if parameter is invalid. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoIndexDemo');
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
let fetchOp = {
fetchColumns: [],
predicates: predicatesForGetAsset
};
//Obtain the uri of the album
let albumFetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified");
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let photoFetchResult = await album.getAssets(fetchOptions);
let expectIndex = 1;
//Obtain the uri of the second file
let photoAsset = await photoFetchResult.getObjectByPosition(expectIndex);
photoAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions)
.then((index) => {
console.info(`getPhotoIndex successfully and index is : ${index}`);
}).catch((err) => {
console.info(`getPhotoIndex failed; error: ${err}`);
})
}
```
### release ### release
release(callback: AsyncCallback&lt;void&gt;): void release(callback: AsyncCallback&lt;void&gt;): void
...@@ -1360,7 +1505,7 @@ Provides APIs for encapsulating file asset attributes. ...@@ -1360,7 +1505,7 @@ Provides APIs for encapsulating file asset attributes.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | | ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
| uri | string | Yes | No | File asset URI, for example, **file://media/image/2**. | | uri | string | Yes | No | File asset URI, for example, **file://media/Photo/1/IMG_datetime_0001/displayName.jpg**. |
| photoType | [PhotoType](#phototype) | Yes | No | Type of the file. | | photoType | [PhotoType](#phototype) | Yes | No | Type of the file. |
| displayName | string | Yes | No | File name, including the file name extension, to display. | | displayName | string | Yes | No | File name, including the file name extension, to display. |
...@@ -2243,6 +2388,282 @@ async function example() { ...@@ -2243,6 +2388,282 @@ async function example() {
} }
``` ```
### getExif<sup>10+</sup>
getExif(): Promise&lt;string&gt;
Obtains a JSON string consisting of the EXIF tags of this JPG image. This API uses a promise to return the result.
**CAUTION**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and **js-apis-photoAccessHelper.md**. These two fields must be passed in via **fetchColumns**.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise&lt;string&gt; | Callback invoked to return the JSON string obtained.|
**Supported EXIF tags**
For details about the EXIF tags, see [image.PropertyKey](js-apis-image.md#propertykey7).
| Key Value | Description |
| --------------------------------------- | ----------------- |
| BitsPerSample | Number of bits per pixel.|
| Orientation | Image orientation.|
| ImageLength | Image length.|
| ImageWidth | Image width.|
| GPSLatitude | GPS latitude of the image.|
| GPSLongitude | GPS longitude of the image.|
| GPSLatitudeRef | Longitude reference, for example, W or E.|
| GPSLongitudeRef | Latitude reference, for example, N or S.|
| DateTimeOriginal | Shooting time.|
| ExposureTime | Exposure time.|
| SceneType | Shooting scene type.|
| ISOSpeedRatings | ISO sensitivity or speed.|
| FNumber | f-number.|
| DateTime | Date and time when the image was last modified.|
| GPSTimeStamp | GPS timestamp.|
| GPSDateStamp | GPS date stamp.|
| ImageDescription | Image description.|
| Make | Camera vendor.|
| Model | Model.|
| PhotoMode | Photo mode.|
| SensitivityType | Sensitivity type.|
| StandardOutputSensitivity | Standard output sensitivity.|
| RecommendedExposureIndex | Recommended exposure index.|
| ApertureValue | Aperture value.|
| MeteringMode | Metering mode.|
| LightSource | Light source.|
| Flash | Flash status.|
| FocalLength | Focal length.|
| UserComment | User comment.|
| PixelXDimension | Pixel X dimension.|
| PixelYDimension | Pixel Y dimension.|
| WhiteBalance | White balance.|
| FocalLengthIn35mmFilm | Focal length in 35 mm film.|
| ExposureBiasValue | Exposure compensation.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [ 'all_exif', photoKeys.USER_COMMENT],
predicates: predicates
};
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let exifMessage = await fileAsset.getExif();
let userCommentKey = 'UserComment';
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
fetchResult.close();
} catch (err) {
console.error('getExifDemoCallback failed with error: ' + err);
}
}
```
### getExif<sup>10+</sup>
getExif(callback: AsyncCallback&lt;string&gt;): void
Obtains a JSON string consisting of the EXIF tags of this JPG image. This API uses an asynchronous callback to return the result.
**CAUTION**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and **ImageVideoKey.USER_COMMENT**. These two fields must be passed in via **fetchColumns**.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the JSON string obtained.|
**Supported EXIF tags**
For details about the EXIF tags, see [image.PropertyKey](js-apis-image.md#propertykey7).
| Key Value | Description |
| --------------------------------------- | ----------------- |
| BitsPerSample | Number of bits per pixel.|
| Orientation | Image orientation.|
| ImageLength | Image length.|
| ImageWidth | Image width.|
| GPSLatitude | GPS latitude of the image.|
| GPSLongitude | GPS longitude of the image.|
| GPSLatitudeRef | Longitude reference, for example, W or E.|
| GPSLongitudeRef | Latitude reference, for example, N or S.|
| DateTimeOriginal | Shooting time.|
| ExposureTime | Exposure time.|
| SceneType | Shooting scene type.|
| ISOSpeedRatings | ISO sensitivity or speed.|
| FNumber | f-number.|
| DateTime | Date and time when the image was last modified.|
| GPSTimeStamp | GPS timestamp.|
| GPSDateStamp | GPS date stamp.|
| ImageDescription | Image description.|
| Make | Camera vendor.|
| Model | Model.|
| PhotoMode | Photo mode.|
| SensitivityType | Sensitivity type.|
| StandardOutputSensitivity | Standard output sensitivity.|
| RecommendedExposureIndex | Recommended exposure index.|
| ApertureValue | Aperture value.|
| MeteringMode | Metering mode.|
| LightSource | Light source.|
| Flash | Flash status.|
| FocalLength | Focal length.|
| UserComment | User comment.|
| PixelXDimension | Pixel X dimension.|
| PixelYDimension | Pixel Y dimension.|
| WhiteBalance | White balance.|
| FocalLengthIn35mmFilm | Focal length in 35 mm film.|
| ExposureBiasValue | Exposure compensation.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [ 'all_exif', photoKeys.USER_COMMENT],
predicates: predicates
};
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let userCommentKey = 'UserComment';
fileAsset.getExif((err, exifMessage) => {
if (exifMessage != undefined) {
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
} else {
console.error('getExif failed, message = ', err);
}
});
fetchResult.close();
} catch (err) {
console.error('getExifDemoCallback failed with error: ' + err);
}
}
```
### setUserComment<sup>10+</sup>
setUserComment(userComment: string): Promise&lt;void&gt;
Sets user comment information of an image or video. This API uses a promise to return the result.
**NOTE**<br>This API can be used to modify the comment information of only images or videos.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| userComment | string | Yes | User comment information to set, which cannot exceed 140 characters.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setUserCommentDemo')
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let userComment = 'test_set_user_comment';
await fileAsset.setUserComment(userComment);
} catch (err) {
console.error('setUserCommentDemoCallback failed with error: ' + err);
}
}
```
### setUserComment<sup>10+</sup>
setUserComment(userComment: string, callback: AsyncCallback&lt;void&gt;): void
Sets user comment information of an image or video. This API uses an asynchronous callback to return the result.
**NOTE**<br>This API can be used to modify the comment information of only images or videos.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| userComment | string | Yes | User comment information to set, which cannot exceed 140 characters.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setUserCommentDemo')
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult = await phAccessHelper.getAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let userComment = 'test_set_user_comment';
fileAsset.setUserComment(userComment, (err) => {
if (err === undefined) {
console.info('setUserComment successfully');
} else {
console.error('setUserComment failed with error: ' + err);
}
});
} catch (err) {
console.error('setUserCommentDemoCallback failed with error: ' + err);
}
}
```
## FetchResult ## FetchResult
Provides APIs to manage the file retrieval result. Provides APIs to manage the file retrieval result.
...@@ -3726,6 +4147,7 @@ Defines the key information about an image or video file. ...@@ -3726,6 +4147,7 @@ Defines the key information about an image or video file.
| DATE_TRASHED | 'date_trashed' | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. **System API**: This is a system API. | | DATE_TRASHED | 'date_trashed' | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. **System API**: This is a system API. |
| HIDDEN | 'hidden' | Whether the file is hidden. **System API**: This is a system API. | | HIDDEN | 'hidden' | Whether the file is hidden. **System API**: This is a system API. |
| CAMERA_SHOT_KEY | 'camera_shot_key' | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.)<br/>**System API**: This is a system API. | | CAMERA_SHOT_KEY | 'camera_shot_key' | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.)<br/>**System API**: This is a system API. |
| USER_COMMENT<sup>10+</sup> | 'user_comment' | User comment information. **System API**: This is a system API. |
## AlbumKeys ## AlbumKeys
......
...@@ -66,7 +66,7 @@ try { ...@@ -66,7 +66,7 @@ try {
if (state == secureElement.ServiceState.DISCONNECTED) { if (state == secureElement.ServiceState.DISCONNECTED) {
console.log("Service state is Disconnected"); console.log("Service state is Disconnected");
} else { } else {
console.log.("Service state is Connected"); console.log("Service state is Connected");
} }
}); });
} catch (e) { } catch (e) {
...@@ -114,7 +114,6 @@ try { ...@@ -114,7 +114,6 @@ try {
try { try {
nfcOmaReaderList = nfcSEService.getReaders(); nfcOmaReaderList = nfcSEService.getReaders();
if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) { if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
nfcOmaReader = this.nfcOmaReaderList[0];
console.log("get reader successfully"); console.log("get reader successfully");
} else { } else {
console.log("get reader failed"); console.log("get reader failed");
...@@ -205,7 +204,6 @@ import secureElement from '@ohos.secureElement'; ...@@ -205,7 +204,6 @@ import secureElement from '@ohos.secureElement';
let nfcSEService = null; let nfcSEService = null;
this.result = "version: "
try { try {
// refer to newSEService for this.nfcSEService // refer to newSEService for this.nfcSEService
console.log("version: " + nfcSEService.getVersion()); console.log("version: " + nfcSEService.getVersion());
...@@ -349,7 +347,7 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -349,7 +347,7 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
nfcOmaReader = null; let nfcOmaReader = null;
try { try {
// refer to SEService.getReaders for this.nfcOmaReader // refer to SEService.getReaders for this.nfcOmaReader
...@@ -584,10 +582,11 @@ import secureElement from '@ohos.secureElement'; ...@@ -584,10 +582,11 @@ import secureElement from '@ohos.secureElement';
let nfcOmaSession = null; let nfcOmaSession = null;
let nfcOmaChannel = null; let nfcOmaChannel = null;
let aidArray = [720, 1080];
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
let getPromise = nfcOmaSession.openBasicChannel(this.aidArray); let getPromise = nfcOmaSession.openBasicChannel(aidArray);
getPromise.then((channel) => { getPromise.then((channel) => {
nfcOmaChannel = channel; nfcOmaChannel = channel;
console.log("openBasicChannel1 get channel successfully"); console.log("openBasicChannel1 get channel successfully");
...@@ -737,7 +736,6 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -737,7 +736,6 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
let nfcOmaSession = null; let nfcOmaSession = null;
let nfcOmaChannel = null; let nfcOmaChannel = null;
let aidArray = [720, 1080]; let aidArray = [720, 1080];
...@@ -915,8 +913,9 @@ if (nfcOmaSession) { ...@@ -915,8 +913,9 @@ if (nfcOmaSession) {
}).catch ((err) => { }).catch ((err) => {
console.log("openLogicChannel3 exception"); console.log("openLogicChannel3 exception");
}) })
} catch (e) { } catch (e) {
console.log("openLogicChannel3 exception:" + e.message); console.log("openLogicChannel3 exception:" + e.message);
}
} }
``` ```
......
...@@ -1393,6 +1393,151 @@ async function example() { ...@@ -1393,6 +1393,151 @@ async function example() {
} }
``` ```
### getPhotoIndex<sup>10+</sup>
getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback&lt;number&gt;): void
Obtains the index of an image or video in an album. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoUri | string | Yes | URI of the media asset whose index is to be obtained.|
| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. |
| options | [FetchOptions](#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search conditions or sorting modes are set, the API cannot be called successfully. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| AsyncCallback&lt;number&gt;| Callback invoked to return the index obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 401 | if parameter is invalid. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoIndexDemo');
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
let fetchOp = {
fetchColumns: [],
predicates: predicatesForGetAsset
};
//Obtain the uri of the album
let albumFetchResult = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubtype.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified");
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let photoFetchResult = await album.getPhotoAssets(fetchOptions);
let expectIndex = 1;
//Obtain the uri of the second file
let photoAsset = await photoFetchResult.getPositionObject(expectIndex);
mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => {
try {
if (err == undefined) {
console.info(`getPhotoIndex successfully and index is : ${index}`);
} else {
console.info(`getPhotoIndex failed;`);
}
} catch (error) {
console.info(`getPhotoIndex failed; error: ${error}`);
}
}
}
```
### getPhotoIndex<sup>10+</sup>
getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise&lt;number&gt;
Obtains the index of an image or video in an album. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoUri | string | Yes | URI of the media asset whose index is to be obtained.|
| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. |
| options | [FetchOptions](#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search conditions or sorting modes are set, the API cannot be called successfully. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise&lt;number&gt;| Promise used to return the index obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 401 | if parameter is invalid. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoIndexDemo');
let predicatesForGetAsset = new dataSharePredicates.DataSharePredicates();
let fetchOp = {
fetchColumns: [],
predicates: predicatesForGetAsset
};
//Obtain the uri of the album
let albumFetchResult = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubtype.FAVORITE, fetchOp);
let album = await albumFetchResult.getFirstObject();
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.orderByAsc("add_modified");
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let photoFetchResult = await album.getPhotoAssets(fetchOptions);
let expectIndex = 1;
//Obtain the uri of the second file
let photoAsset = await photoFetchResult.getPositionObject(expectIndex);
mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions)
.then((index) => {
console.info(`getPhotoIndex successfully and index is : ${index}`);
}).catch((err) => {
console.info(`getPhotoIndex failed; error: ${err}`);
})
}
```
### release ### release
release(callback: AsyncCallback&lt;void&gt;): void release(callback: AsyncCallback&lt;void&gt;): void
...@@ -1684,7 +1829,7 @@ Provides APIs for encapsulating file asset attributes. ...@@ -1684,7 +1829,7 @@ Provides APIs for encapsulating file asset attributes.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | | ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
| uri | string | Yes | No | File asset URI, for example, **file://media/image/2**. | | uri | string | Yes | No | File asset URI, for example, **file://media/Photo/1/IMG_datetime_0001/displayName.jpg**. |
| fileType | [FileType](#filetype) | Yes | No | Type of the file. | | fileType | [FileType](#filetype) | Yes | No | Type of the file. |
| displayName | string | Yes | Yes | File name, including the file name extension, to display. | | displayName | string | Yes | Yes | File name, including the file name extension, to display. |
...@@ -2350,6 +2495,282 @@ async function example() { ...@@ -2350,6 +2495,282 @@ async function example() {
} }
``` ```
### getExif<sup>10+</sup>
getExif(): Promise&lt;string&gt;
Obtains a JSON string consisting of the exchangeable image file format (EXIF) tags of this JPG image. This API uses a promise to return the result.
**CAUTION**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and **ImageVideoKey.USER_COMMENT**. These two fields must be passed in via **fetchColumns**.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise&lt;string&gt; | Promise used to return the JSON string obtained.|
**Supported EXIF tags**
For details about the EXIF tags, see [image.PropertyKey](js-apis-image.md#propertykey7).
| Key Value | Description |
| --------------------------------------- | ----------------- |
| BitsPerSample | Number of bits per pixel.|
| Orientation | Image orientation.|
| ImageLength | Image length.|
| ImageWidth | Image width.|
| GPSLatitude | GPS latitude of the image.|
| GPSLongitude | GPS longitude of the image.|
| GPSLatitudeRef | Longitude reference, for example, W or E.|
| GPSLongitudeRef | Latitude reference, for example, N or S.|
| DateTimeOriginal | Shooting time.|
| ExposureTime | Exposure time.|
| SceneType | Shooting scene type.|
| ISOSpeedRatings | ISO sensitivity or speed.|
| FNumber | f-number.|
| DateTime | Date and time when the image was last modified.|
| GPSTimeStamp | GPS timestamp.|
| GPSDateStamp | GPS date stamp.|
| ImageDescription | Image description.|
| Make | Camera vendor.|
| Model | Model.|
| PhotoMode | Photo mode.|
| SensitivityType | Sensitivity type.|
| StandardOutputSensitivity | Standard output sensitivity.|
| RecommendedExposureIndex | Recommended exposure index.|
| ApertureValue | Aperture value.|
| MeteringMode | Metering mode.|
| LightSource | Light source.|
| Flash | Flash status.|
| FocalLength | Focal length.|
| UserComment | User comment.|
| PixelXDimension | Pixel X dimension.|
| PixelYDimension | Pixel Y dimension.|
| WhiteBalance | White balance.|
| FocalLengthIn35mmFilm | Focal length in 35 mm film.|
| ExposureBiasValue | Exposure compensation.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [ 'all_exif', ImageVideoKey.USER_COMMENT],
predicates: predicates
};
let fetchResult = await mgr.getPhotoAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let exifMessage = await fileAsset.getExif();
let userCommentKey = 'UserComment';
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
fetchResult.close();
} catch (err) {
console.error('getExifDemoCallback failed with error: ' + err);
}
}
```
### getExif<sup>10+</sup>
getExif(callback: AsyncCallback&lt;string&gt;): void
Obtains a JSON string consisting of the EXIF tags of this JPG image. This API uses an asynchronous callback to return the result.
**CAUTION**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and **ImageVideoKey.USER_COMMENT**. These two fields must be passed in via **fetchColumns**.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the JSON string obtained.|
**Supported EXIF tags**
For details about the EXIF tags, see [image.PropertyKey](js-apis-image.md#propertykey7).
| Key Value | Description |
| --------------------------------------- | ----------------- |
| BitsPerSample | Number of bits per pixel.|
| Orientation | Image orientation.|
| ImageLength | Image length.|
| ImageWidth | Image width.|
| GPSLatitude | GPS latitude of the image.|
| GPSLongitude | GPS longitude of the image.|
| GPSLatitudeRef | Longitude reference, for example, W or E.|
| GPSLongitudeRef | Latitude reference, for example, N or S.|
| DateTimeOriginal | Shooting time.|
| ExposureTime | Exposure time.|
| SceneType | Shooting scene type.|
| ISOSpeedRatings | ISO sensitivity or speed.|
| FNumber | f-number.|
| DateTime | Date and time when the image was last modified.|
| GPSTimeStamp | GPS timestamp.|
| GPSDateStamp | GPS date stamp.|
| ImageDescription | Image description.|
| Make | Camera vendor.|
| Model | Model.|
| PhotoMode | Photo mode.|
| SensitivityType | Sensitivity type.|
| StandardOutputSensitivity | Standard output sensitivity.|
| RecommendedExposureIndex | Recommended exposure index.|
| ApertureValue | Aperture value.|
| MeteringMode | Metering mode.|
| LightSource | Light source.|
| Flash | Flash status.|
| FocalLength | Focal length.|
| UserComment | User comment.|
| PixelXDimension | Pixel X dimension.|
| PixelYDimension | Pixel Y dimension.|
| WhiteBalance | White balance.|
| FocalLengthIn35mmFilm | Focal length in 35 mm film.|
| ExposureBiasValue | Exposure compensation.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('getExifDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [ 'all_exif', ImageVideoKey.USER_COMMENT],
predicates: predicates
};
let fetchResult = await mgr.getPhotoAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let userCommentKey = 'UserComment';
fileAsset.getExif((err, exifMessage) => {
if (exifMessage != undefined) {
let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]);
} else {
console.error('getExif failed, message = ', err);
}
});
fetchResult.close();
} catch (err) {
console.error('getExifDemoCallback failed with error: ' + err);
}
}
```
### setUserComment<sup>10+</sup>
setUserComment(userComment: string): Promise&lt;void&gt;
Sets user comment information of an image or video. This API uses a promise to return the result.
**NOTE**<br>This API can be used to modify the comment information of only images or videos.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| userComment | string | Yes | User comment information to set, which cannot exceed 140 characters.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setUserCommentDemo')
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult = await mgr.getPhotoAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let userComment = 'test_set_user_comment';
await fileAsset.setUserComment(userComment);
} catch (err) {
console.error('setUserCommentDemoCallback failed with error: ' + err);
}
}
```
### setUserComment<sup>10+</sup>
setUserComment(userComment: string, callback: AsyncCallback&lt;void&gt;): void
Sets user comment information of an image or video. This API uses an asynchronous callback to return the result.
**NOTE**<br>This API can be used to modify the comment information of only images or videos.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| userComment | string | Yes | User comment information to set, which cannot exceed 140 characters.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setUserCommentDemo')
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult = await mgr.getPhotoAssets(fetchOptions);
let fileAsset = await fetchResult.getFirstObject();
let userComment = 'test_set_user_comment';
fileAsset.setUserComment(userComment, (err) => {
if (err === undefined) {
console.info('setUserComment successfully');
} else {
console.error('setUserComment failed with error: ' + err);
}
});
} catch (err) {
console.error('setUserCommentDemoCallback failed with error: ' + err);
}
}
```
## FetchResult ## FetchResult
Provides APIs to manage the file retrieval result. Provides APIs to manage the file retrieval result.
...@@ -3962,6 +4383,7 @@ Defines the key information about an image or video file. ...@@ -3962,6 +4383,7 @@ Defines the key information about an image or video file.
| DATE_TRASHED<sup>10+</sup> | date_trashed | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. | | DATE_TRASHED<sup>10+</sup> | date_trashed | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. |
| HIDDEN<sup>10+</sup> | hidden | Whether the file is hidden. | | HIDDEN<sup>10+</sup> | hidden | Whether the file is hidden. |
| CAMERA_SHOT_KEY<sup>10+</sup> | camera_shot_key | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) | | CAMERA_SHOT_KEY<sup>10+</sup> | camera_shot_key | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) |
| USER_COMMENT<sup>10+</sup> | user_comment | User comment information. |
## AlbumKey ## AlbumKey
......
...@@ -1054,7 +1054,7 @@ Checks whether the specified authentication capability is supported. ...@@ -1054,7 +1054,7 @@ Checks whether the specified authentication capability is supported.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------- | ---------------------------------- | ---- | -------------------------- | | -------------- | ---------------------------------- | ---- | -------------------------- |
| authType | [UserAuthType](#userauthtype8) | Yes | Authentication type. Only **FACE** is supported.| | authType | [UserAuthType](#userauthtype8) | Yes | Authentication type.|
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Authentication trust level. | | authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Authentication trust level. |
**Error codes** **Error codes**
......
# Account Subsystem Changelog
## cl.account_os_account.1 Deletion of App Account Authorization Interfaces
**Change Impact**
Apps developed based on earlier versions cannot use the account authorization capability.
**Key API/Component Changes**
Involved interfaces:
interface/sdk-js/api/@ohos.account.appAccount.d.ts:
```js
enum AccountCapabilityType
```
```js
class AccountCapabilityProvider
```
```js
class AuthorizationProvider extends AccountCapabilityProvider
```
```js
interface AuthorizationProviderInfo
```
```js
class AccountCapabilityRequest
```
```js
class AccountCapabilityResponse
```
```js
class AccountCapabilityScheduler
```
interface/sdk-js/api/@ohos.account.appAccount.AuthorizationExtensionAbility.d.ts:
```js
export default class AuthorizationExtensionAbility extends ExtensionAbility
```
```js
declare interface AuthorizationRequest
```
```js
declare interface AuthorizationCallback
```
After change:
All the involved interfaces are deleted.
**Adaptation Guide**
The deleted interfaces cannot be used any longer. Delete the corresponding functions accordingly.
...@@ -6,11 +6,11 @@ Deprecated **X509Cert.getSerialNumber()** and replaced it with **X509Cert.getCer ...@@ -6,11 +6,11 @@ Deprecated **X509Cert.getSerialNumber()** and replaced it with **X509Cert.getCer
**Change Impact** **Change Impact**
**X509Cert.getSerialNumber()** is deprecated since API version 10. **X509Cert.getCertSerialNumber()** should be used to replace **X509Cert.getSerialNumber()** in application development. The API function remains unchanged. Since API version 10, use **X509Cert.getCertSerialNumber()** instead of **X509Cert.getSerialNumber()** in application development. The API function remains unchanged.
**Key API/Component Changes** **Key API/Component Changes**
API before change: Before change:
```js ```js
interface X509Cert { interface X509Cert {
...@@ -20,7 +20,7 @@ interface X509Cert { ...@@ -20,7 +20,7 @@ interface X509Cert {
} }
``` ```
API after change: After change:
```js ```js
interface X509Cert { interface X509Cert {
......
# Wi-Fi Subsystem Changelog
## 1 Permission Change
1. The location permission is not required if a random MAC is returned.
1. The GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned.
| API| Permission|
| -------- | ---------------------------- |
|**function** getCandidateConfigs(): Array<WifiDeviceConfig>; | 1. The location permission is not required.|
|**function** getDeviceConfigs(): Array<WifiDeviceConfig>; | 1. The location permission is not required.|
|**function** getStations(): Array<StationInfo>; | 1. The location permission is not required. <br/>2. A random MAC address is returned (the GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned). |
| **function** getCurrentP2pGroup(): Promise<WifiP2pGroupInfo>; | 1. The location permission is not required.|
| **function** getCurrentP2pGroup(callback: AsyncCallback<WifiP2pGroupInfo>): **void**; | 1. The location permission is not required.|
| **function** getP2pPeerDevices(): Promise<WifiP2pDevice[]>; | 1. The location permission is not required. <br/>2. A random MAC address is returned (the GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned). |
| **function** getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): **void**; | 1. The location permission is not required. <br/>2. A random MAC address is returned (the GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned). |
| **function** p2pConnect(config: WifiP2PConfig): **void**; | 1. The location permission is not required.|
| **function** startDiscoverDevices(): **void**; | 1. The location permission is not required.|
| **function** getP2pGroups(): Promise<Array<WifiP2pGroupInfo>>; | 1. The location permission is not required.|
| **function** getP2pGroups(callback: AsyncCallback<Array<WifiP2pGroupInfo>>): **void**; | 1. The location permission is not required.|
| **function** on(**type**: "p2pDeviceChange", callback: Callback<WifiP2pDevice>): **void**; | 1. The location permission is not required. <br/>2. A random MAC address is returned (the GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned). |
| **function** off(**type**: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): **void**; | 1. The location permission is not required. <br/>2. A random MAC address is returned (the GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned). |
| **function** on(**type**: "p2pPeerDeviceChange", callback: Callback<WifiP2pDevice[]>): **void**; | 1. The location permission is not required. <br/>2. A random MAC address is returned (the GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned). |
| **function** off(**type**: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): **void**; | 1. The location permission is not required. <br/>2. A random MAC address is returned (the GET_WIFI_PEERS_MAC permission is required if a real MAC address is returned). |
## 2 Added APIs
| API| Description|
|------|---------|
| **function** startScan(): **void**; | Starts a scan.|
| **function** getScanInfoList(): Array<WifiScanInfo>; | Obtains the scan list. |
| **function** setScanAlwaysAllowed(isScanAlwaysAllowed: boolean): **void**; | Sets whether to always allow Wi-Fi scanning. |
| **function** getScanAlwaysAllowed(): boolean; | Obtains the Wi-Fi scan settings on the background. |
| **function** getIpv6Info(): Ipv6Info; | Obtains IPv6 address information. |
| **function** isBandTypeSupported(bandType: WifiBandType): boolean; | Checks whether BandType is supported.|
| **function** get5GChannelList(): Array<**number**>; | Obtains the 5G channel list. |
| **function** getDisconnectedReason(): DisconnectedReason; | Obtains the reason for network disconnection. |
## 3 Deprecated APIs
| API |Description |
| ------------- |-------------------------------------------------------- |
| **function** scan(): **void**; | Use **startScan** instead.|
| **function** getScanResults(): Promise<Array<WifiScanInfo>>; | Use **getScanInfoList** instead.|
| **function** getScanResults(callback: AsyncCallback<Array<WifiScanInfo>>): **void**; | Use **getScanInfoList** instead.|
| **function** getScanResultsSync(): Array<WifiScanInfo>; | Use **getScanInfoList** instead.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册