openharmony 鸿蒙 js-apis-ability-dataUriUtils

2025-06-12 浏览 (1)

@ohos.ability.dataUriUtils (DataUriUtils)

The DataUriUtils module provides APIs to process URI objects. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI.

NOTE

The APIs of this module are supported since API version 7 and deprecated since API version 9. You are advised to use @ohos.app.ability.dataUriUtils instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import dataUriUtils from '@ohos.ability.dataUriUtils';

dataUriUtils.getId

getId(uri: string): number

Obtains the ID attached to the end of a given URI.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
uristringYesTarget URI object.

Return value

TypeDescription
numberID obtained.

Example

import dataUriUtils from '@ohos.ability.dataUriUtils';

let id = dataUriUtils.getId('com.example.dataUriUtils/1221');

dataUriUtils.attachId

attachId(uri: string, id: number): string

Attaches an ID to the end of a given URI.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
uristringYesTarget URI object.
idnumberYesID to be attached.

Return value

TypeDescription
stringURI object with the ID attached.

Example

import dataUriUtils from '@ohos.ability.dataUriUtils';

let id = 1122;
let uri = dataUriUtils.attachId(
    'com.example.dataUriUtils',
	id,
);

dataUriUtils.deleteId

deleteId(uri: string): string

Deletes the ID from the end of a given URI.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
uristringYesURI object from which the ID is to be deleted.

Return value

TypeDescription
stringURI object with the ID deleted.

Example

import dataUriUtils from '@ohos.ability.dataUriUtils';

let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');

dataUriUtils.updateId

updateId(uri: string, id: number): string

Updates the ID in a given URI.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
uristringYesTarget URI object.
idnumberYesNew ID.

Return value

TypeDescription
stringURI object with the new ID.

Example

import dataUriUtils from '@ohos.ability.dataUriUtils';

let id = 1122;
let uri = dataUriUtils.updateId(
    'com.example.dataUriUtils/1221',
	id
);

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/senksA