可以设置ALIAS关键资产别名,删除的时候指定别名删除单条数据。参考删除关键资产(ArkTS)import { asset } from '@kit.AssetStoreKit'; import { util } from '@kit.ArkTS'; import { BusinessError } from '@kit.BasicServicesKit'; function stringToArray(str: string): Uint8Array { let textEncoder = new util.TextEncoder(); return textEncoder.encodeInto(str); } let query: asset.AssetMap = new Map(); query.set(asset.Tag.ALIAS, stringToArray('demo_alias')); // 此处指定别名删除单条数据,也可不指定别名删除多条数据 try { asset.remove(query).then(() => { console.info(`Asset removed successfully.`); }).catch((err: BusinessError) => { console.error(`Failed to remove Asset. Code is ${err.code}, message is ${err.message}`); }); } catch (error) { let err = error as BusinessError; console.error(`Failed to remove Asset. Code is ${err.code}, message is ${err.message}`); }
可以设置ALIAS关键资产别名,删除的时候指定别名删除单条数据。
参考删除关键资产(ArkTS)