openharmony 鸿蒙 js-apis-data-uniformTypeDescriptor-sys

2026-08-25 浏览 (1)

@ohos.data.uniformTypeDescriptor (标准化数据定义与描述)(系统接口)

本模块提供标准化数据类型的注册与注销能力。

说明:

导入模块

import { uniformTypeDescriptor } from '@kit.ArkData';

uniformTypeDescriptor.registerTypeDescriptors22+

registerTypeDescriptors(typeDescriptors: Array<TypeDescriptor>): Promise<void>

注册一组标准化数据类型到系统中。使用Promise异步回调。

需要权限: ohos.permission.MANAGE_DYNAMIC_UTD_TYPE

系统能力: SystemCapability.DistributedDataManager.UDMF.Core

原子化服务API: 从API version 22开始,该接口支持在原子化服务中使用。

系统接口: 此接口为系统接口。

参数:

参数名类型必填说明
typeDescriptorsArray<TypeDescriptor>待注册的标准化数据类型描述符列表。列表不可为空,其中元素个数不超过50。单个应用注册的标准化数据类型描述符数量总计不超过200。
TypeDescriptor格式要求:
1.typeId不可为空字符串,长度不超过127且仅包含字母、数字、中划线(-)和点号(.)。
2.belongingToTypes中元素个数不超过50。每项不可为空字符串,长度不超过127。
3.description/referenceURL/iconFile每项长度不超过255。
4.filenameExtensions中元素个数不超过50。每项不可为空字符串,长度不超过127且首字符为点号。
5.mimeTypes中元素个数不超过50。每项不可为空字符串,长度不超过127。
TypeDescriptor内容要求:
1.typeId必须唯一,不能与已注册类型的typeId重复。
2.typeId必须以当前应用的包名开头。
3.belongingToTypes中的标准化数据类型ID必须为预置数据类型或本次注册的其他标准化数据类型的typeId。
4.标准化数据类型之间不能存在循环依赖关系。

返回值:

类型说明
Promise<void>Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见通用错误码统一数据管理框架错误码

错误码ID错误信息
201Permission verification failed. The application does not have the permission required to call the API.
202Permission denied, non-system app called the system api.
20400002The format of one or more typeDescriptors are invalid.
20400003The content of one or more typeDescriptors violate rules.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
    const typeDescriptor = new uniformTypeDescriptor.TypeDescriptor();
    typeDescriptor.typeId = 'com.example.myHap.image';
    typeDescriptor.belongingToTypes = ['general.image'];
    typeDescriptor.filenameExtensions = ['.myImage'];
    typeDescriptor.mimeTypes = ['application/myImage'];
    typeDescriptor.description = 'myHap defined image type';
    await uniformTypeDescriptor.registerTypeDescriptors([typeDescriptor]);
    console.info('Type descriptors registered successfully.');
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`registerTypeDescriptors throws an exception. code is ${error.code}, message is ${error.message} `);
}

uniformTypeDescriptor.unregisterTypeDescriptors22+

unregisterTypeDescriptors(typeIds: Array<string>): Promise<void>

从系统中注销一个或多个标准化数据类型。使用Promise异步回调。

需要权限: ohos.permission.MANAGE_DYNAMIC_UTD_TYPE

系统能力: SystemCapability.DistributedDataManager.UDMF.Core

原子化服务API: 从API version 22开始,该接口支持在原子化服务中使用。

系统接口: 此接口为系统接口。

参数:

参数名类型必填说明
typeIdsArray<string>待注销的typeId列表。列表不可为空,其中元素个数不超过50。
typeId约束限制:
1.typeId对应的标准化数据类型必须在系统中已注册;
2.typeId必须以当前应用的包名开头;
3.typeId对应的标准化数据类型必须已通过registerTypeDescriptors接口注册。

返回值:

类型说明
Promise<void>Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见通用错误码统一数据管理框架错误码

错误码ID错误信息
201Permission verification failed. The application does not have the permission required to call the API.
202Permission denied, non-system app called the system api.
20400004One or more typeIds are invalid or do not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
    const typeIds = ['com.example.myHap.image'];
    await uniformTypeDescriptor.unregisterTypeDescriptors(typeIds);
    console.info('Type descriptors unregistered successfully.');
} catch (e) {
    const error: BusinessError = e as BusinessError;
    console.error(`unregisterTypeDescriptors throws an exception. code is ${error.code}, message is ${error.message}`);
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-distributedKVStore-sys

openharmony 鸿蒙 capi-oh-preferences-h

openharmony 鸿蒙 capi-udmf-oh-udshyperlink

openharmony 鸿蒙 js-apis-data-dataSharePredicates

openharmony 鸿蒙 capi-udmf-oh-udsappitem

openharmony 鸿蒙 capi-rdb-oh-data-vbuckets

openharmony 鸿蒙 capi-rdb-oh-predicates

openharmony 鸿蒙 capi-rdb-oh-data-value

openharmony 鸿蒙 capi-preferences-oh-preferencespair

openharmony 鸿蒙 errorcode-datashare

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