harmony 鸿蒙Removing Assets (C/C++)

  • 2025-06-12
  • 浏览 (5)

Removing Assets (C/C++)

Available APIs

You can use OH_Asset_Remove to remove assets. If the asset alias is specified, the specified asset will be removed. If no asset alias is specified, all assets will be removed.

The following table describes the asset attributes.

NOTE

In the following table, the attributes starting with ASSET_TAG_DATA_LABEL are custom asset attributes reserved. These attributes are not encrypted. Therefore, do not put personal data in these attributes.

Attribute Name (Asset_Tag) Attribute Content (Asset_Value) Mandatory Description
ASSET_TAG_ALIAS Type: uint8[]
Length: 1-256 bytes
No Asset alias, which uniquely identifies an asset.
ASSET_TAG_ACCESSIBILITY Type: uint32_t
Value range: see Asset_Accessibility
No Access control based on the lock screen status.
ASSET_TAG_REQUIRE_PASSWORD_SET Type: bool No Whether the asset is accessible only when a lock screen password is set.
ASSET_TAG_AUTH_TYPE Type: uint32_t
Value range: see Asset_AuthType
No Type of user authentication required for accessing the asset.
ASSET_TAG_SYNC_TYPE Type: uint32_t
Value range: see Asset_SyncType
No Type of sync supported by the asset.
ASSET_TAG_IS_PERSISTENT Type: bool No Whether to retain the asset when the application is uninstalled.
ASSET_TAG_DATA_LABEL_CRITICAL_1 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service with integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_CRITICAL_2 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service with integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_CRITICAL_3 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service with integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_CRITICAL_4 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service with integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_NORMAL_1 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service without integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_NORMAL_2 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service without integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_NORMAL_3 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service without integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_NORMAL_4 Type: uint8[]
Length: 1-2048 bytes
No Asset attribute information customized by the service without integrity protection.
NOTE: The data length is 1 to 512 bytes before API version 12.
ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_112+ Type: uint8[]
Length: 1-2048 bytes
No Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.
ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_212+ Type: uint8[]
Length: 1-2048 bytes
No Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.
ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_312+ Type: uint8[]
Length: 1-2048 bytes
No Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.
ASSET_TAG_DATA_LABEL_NORMAL_LOCAL_412+ Type: uint8[]
Length: 1-2048 bytes
No Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.
ASSET_TAG_REQUIRE_ATTR_ENCRYPTED14+ Type: bool No Whether to remove the customized asset attribute information that is encrypted. By default, the unencrypted, customized asset attribute information is removed.
ASSET_TAG_GROUP_ID18+ Type: Uint8[]
Length: 7-127 bytes
No Group to which the asset to be removed belongs. By default, this parameter is not specified.

Example

Remove asset demo_alias.

For details about how to remove an asset in a group, see Removing an Asset from a Group.

  1. Add the dynamic library in the CMake script.

    target_link_libraries(entry PUBLIC libasset_ndk.z.so)
    
  2. Add an asset. “`c #include

#include “asset/asset_api.h”

void RemoveAsset() { static const char *ALIAS = “demo_alias”; Asset_Blob alias = { (uint32_t)(strlen(ALIAS)), (uint8_t *)ALIAS };

  Asset_Attr attr[] = {
     { .tag = ASSET_TAG_ALIAS, .value.blob = alias }, // Specify the asset alias to remove a single asset. To remove all assets, leave the alias unspecified.
  };

  int32_t ret = OH_Asset_Remove(attr, sizeof(attr) / sizeof(attr[0]));
  if (ret == ASSET_SUCCESS) {
     // Asset removed successfully.
  } else {
     // Failed to remove Asset.
  }

} “`

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Asset Store Kit (Asset Store Service)

harmony 鸿蒙Performing Asset Operations in Specified User Space (for System Applications Only)

harmony 鸿蒙Adding an Asset (ArkTS)

harmony 鸿蒙Managing Assets in a Group

harmony 鸿蒙Querying an Asset with User Authentication (ArkTS)

harmony 鸿蒙Querying Assets (ArkTS)

harmony 鸿蒙Removing Assets (ArkTS)

harmony 鸿蒙Updating an Asset (ArkTS)

harmony 鸿蒙Adding an Asset (C/C++)

harmony 鸿蒙Managing Assets in a Group

0  赞