@ohos.data.uniformTypeDescriptor (Uniform Data Definition and Description)

The uniformTypeDescriptor module abstracts and defines OpenHarmony uniform data types.

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

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';

UniformDataType

Enumerates OpenHarmony uniform data types. Some data types are related. For example, the JPEG type belongs to the IMAGE type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Name Value Description
ENTITY11+ 'general.entity' Base physical storage type.
This type is uncategorized.
OBJECT11+ 'general.object' Base logical content type.
This type is uncategorized.
COMPOSITE_OBJECT11+ 'general.composite-object' Base composite content type. For example, a PDF file that contains text and image.
This type belongs to OBJECT.
TEXT 'general.text' Base text type.
This type belongs to OBJECT.
PLAIN_TEXT 'general.plain-text' Text without specific encoding or identifier.
This type belongs to TEXT.
HTML 'general.html' HTML.
This type belongs to TEXT.
HYPERLINK 'general.hyperlink' Hyperlink.
This type belongs to TEXT.
XML11+ 'general.xml' XML.
This type belongs to TEXT.
SOURCE_CODE11+ 'general.source-code' Base source code type.
This type belongs to PLAIN_TEXT.
SCRIPT11+ 'general.script' Source code in any scripting language.
This type belongs to SOURCE_CODE.
SHELL_SCRIPT11+ 'general.shell-script' Shell script.
This type belongs to SCRIPT.
CSH_SCRIPT11+ 'general.csh-script' C shell script.
This type belongs to SHELL_SCRIPT.
PERL_SCRIPT11+ 'general.perl-script' Perl script.
This type belongs to SHELL_SCRIPT.
PHP_SCRIPT11+ 'general.php-script' PHP script.
This type belongs to SHELL_SCRIPT.
PYTHON_SCRIPT11+ 'general.python-script' Python script.
This type belongs to SHELL_SCRIPT.
RUBY_SCRIPT11+ 'general.ruby-script' Ruby script.
This type belongs to SHELL_SCRIPT.
TYPE_SCRIPT11+ 'general.type-script' TypeScript source code.
This type belongs to SCRIPT.
JAVA_SCRIPT11+ 'general.java-script' JavaScript source code.
This type belongs to SCRIPT.
C_HEADER11+ 'general.c-header' Header file in C.
This type belongs to SOURCE_CODE.
C_SOURCE11+ 'general.c-source' Source code in C.
This type belongs to SOURCE_CODE.
C_PLUS_PLUS_HEADER11+ 'general.c-plus-plus-header' Header file in C++.
This type belongs to SOURCE_CODE.
C_PLUS_PLUS_SOURCE11+ 'general.c-plus-plus-source' Source code in C++.
This type belongs to SOURCE_CODE.
JAVA_SOURCE11+ 'general.java-source' Source code in Java.
This type belongs to SOURCE_CODE.
EBOOK11+ 'general.ebook' Base eBook file format type.
This type belongs to COMPOSITE_OBJECT.
EPUB11+ 'general.epub' Electronic publication (EPUB).
This type belongs to EBOOK.
AZW11+ 'com.amazon.azw' AZW.
This type belongs to EBOOK.
AZW311+ 'com.amazon.azw3' AZW3.
This type belongs to EBOOK.
KFX11+ 'com.amazon.kfx' KFX.
This type belongs to EBOOK.
MOBI11+ 'com.amazon.mobi' MOBI.
This type belongs to EBOOK.
MEDIA11+ 'general.media' Base media type.
This type belongs to OBJECT.
IMAGE 'general.image' Image.
This type belongs to MEDIA.
JPEG11+ 'general.jpeg' JPEG.
This type belongs to IMAGE.
PNG11+ 'general.png' PNG.
This type belongs to IMAGE.
RAW_IMAGE11+ 'general.raw-image' Raw image.
This type belongs to IMAGE.
TIFF11+ 'general.tiff' TIFF.
This type belongs to IMAGE.
BMP11+ 'com.microsoft.bmp' BMP.
This type belongs to IMAGE.
ICO11+ 'com.microsoft.ico' Windows icon.
This type belongs to IMAGE.
PHOTOSHOP_IMAGE11+ 'com.adobe.photoshop-image' Adobe Photoshop image.
This type belongs to IMAGE.
AI_IMAGE11+ 'com.adobe.illustrator.ai-image' Adobe Illustrator image (.ai).
This type belongs to IMAGE.
WORD_DOC11+ 'com.microsoft.word.doc' Microsoft Word.
This type belongs to COMPOSITE_OBJECT.
EXCEL11+ 'com.microsoft.excel.xls' Microsoft Excel.
This type belongs to COMPOSITE_OBJECT.
PPT11+ 'com.microsoft.powerpoint.ppt' Microsoft PowerPoint.
This type belongs to COMPOSITE_OBJECT.
PDF11+ 'com.adobe.pdf' PDF.
This type belongs to COMPOSITE_OBJECT.
POSTSCRIPT11+ 'com.adobe.postscript' PostScript.
This type belongs to COMPOSITE_OBJECT.
ENCAPSULATED_POSTSCRIPT11+ 'com.adobe.encapsulated-postscript' Encapsulated PostScript.
This type belongs to POSTSCRIPT.
VIDEO 'general.video' Base video type.
This type belongs to MEDIA.
AVI11+ 'general.avi' AVI.
This type belongs to VIDEO.
MPEG11+ 'general.mpeg' MPGE-1 or MPGE-2.
This type belongs to VIDEO.
MPEG411+ 'general.mpeg-4' MPGE-4.
This type belongs to VIDEO.
VIDEO_3GPP11+ 'general.3gpp' 3GP (3GPP file format).
This type belongs to VIDEO.
VIDEO_3GPP211+ 'general.3gpp2' 3G2 (3GPP2 file format).
This type belongs to VIDEO.
WINDOWS_MEDIA_WM11+ 'com.microsoft.windows-media-wm' Windows WM format.
This type belongs to VIDEO.
WINDOWS_MEDIA_WMV11+ 'com.microsoft.windows-media-wmv' Windows WMV format.
This type belongs to VIDEO.
WINDOWS_MEDIA_WMP11+ 'com.microsoft.windows-media-wmp' Windows WMP format.
This type belongs to VIDEO.
AUDIO 'general.audio' Base audio type.
This type belongs to MEDIA.
AAC11+ 'general.aac' AAC.
This type belongs to AUDIO.
AIFF11+ 'general.aiff' AIFF.
This type belongs to AUDIO.
ALAC11+ 'general.alac' ALAC.
This type belongs to AUDIO.
FLAC11+ 'general.flac' FLAC.
This type belongs to AUDIO.
MP311+ 'general.mp3' MP3.
This type belongs to AUDIO.
OGG11+ 'general.ogg' OGG.
This type belongs to AUDIO.
PCM11+ 'general.pcm' PCM.
This type belongs to AUDIO.
WINDOWS_MEDIA_WMA11+ 'com.microsoft.windows-media-wma' Windows WMA.
This type belongs to AUDIO.
WAVEFORM_AUDIO11+ 'com.microsoft.waveform-audio' Windows Waveform.
This type belongs to AUDIO.
WINDOWS_MEDIA_WMX11+ 'com.microsoft.windows-media-wmx' Windows WMX.
This type belongs to AUDIO.
WINDOWS_MEDIA_WVX11+ 'com.microsoft.windows-media-wvx' Windows WVX.
This type belongs to AUDIO.
WINDOWS_MEDIA_WAX11+ 'com.microsoft.windows-media-wax' Windows WAX.
This type belongs to AUDIO.
FILE 'general.file' Base file type.
This type belongs to ENTITY.
DIRECTORY11+ 'general.directory' Base directory type.
This type belongs to ENTITY.
FOLDER 'general.folder' Base folder type.
This type belongs to DIRECTORY.
SYMLINK11+ 'general.symlink' Base symbolic type.
This type belongs to ENTITY.
ARCHIVE11+ 'general.archive' Base archive file type.
This type belongs to OBJECT.
BZ2_ARCHIVE11+ 'general.bz2-archive' BZ2.
This type belongs to ARCHIVE.
DISK_IMAGE11+ 'general.disk-image' Base type of any file that can be mounted as a volume.
This type belongs to ARCHIVE.
TAR_ARCHIVE11+ 'general.tar-archive' TAR.
This type belongs to ARCHIVE.
ZIP_ARCHIVE11+ 'general.zip-archive' ZIP.
This type belongs to ARCHIVE.
JAVA_ARCHIVE11+ 'com.sun.java-archive' JAR (Java archive).
This type belongs to ARCHIVE.
GNU_TAR_ARCHIVE11+ 'org.gnu.gnu-tar-archive' GUN archive.
This type belongs to ARCHIVE.
GNU_ZIP_ARCHIVE11+ 'org.gnu.gnu-zip-archive' GZIP archive.
This type belongs to ARCHIVE.
GNU_ZIP_TAR_ARCHIVE11+ 'org.gnu.gnu-zip-tar-archive' GZIP TAR.
This type belongs to ARCHIVE.
CALENDAR11+ 'general.calendar' Base calendar type.
This type belongs to OBJECT.
CONTACT11+ 'general.contact' Base contact type.
This type belongs to OBJECT.
DATABASE11+ 'general.database' Base database file type.
This type belongs to OBJECT.
MESSAGE11+ 'general.message' Base message type.
This type belongs to OBJECT.
VCARD11+ 'general.vcard' Base electronic business card type.
This type belongs to OBJECT.
NAVIGATION11+ 'general.navigation' Base navigation data type.
This type belongs to OBJECT.
LOCATION11+ 'general.location' Location data.
This type belongs to NAVIGATION.
OPENHARMONY_FORM 'openharmony.form' Widget defined for OpenHarmony.
This type belongs to OBJECT.
OPENHARMONY_APP_ITEM 'openharmony.app-item' Home screen icon defined for OpenHarmony.
This type belongs to OBJECT.
OPENHARMONY_PIXEL_MAP 'openharmony.pixel-map' Pixel map defined by OpenHarmony.
This type belongs to IMAGE.
OPENHARMONY_ATOMIC_SERVICE11+ 'openharmony.atomic-service' Atomic service defined for OpenHarmony.
This type belongs to OBJECT.
OPENHARMONY_PACKAGE11+ 'openharmony.package' Package defined for OpenHarmony (compressed folder).
This type belongs to DIRECTORY.
OPENHARMONY_HAP11+ 'openharmony.hap' Ability package defined for OpenHarmony.
This type belongs to OPENHARMONY_PACKAGE.

TypeDescriptor11+

Provides attributes and APIs for describing a uniform data type and its relationship with other uniform data types.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Name Type Readable Writable Description
typeId11+ string Yes No ID of the uniform data type, which is a value of UniformDataType.
belongingToTypes11+ Array<string> Yes No Data types to which the uniform data type belongs.
description11+ string Yes No Brief description of the uniform data type.
referenceURL11+ string Yes No URL of the link to the reference (detailed information) of the uniform data type.
iconFile11+ string Yes No File path of the default icon for the uniform data type. An empty string means the uniform data type has no default icon. The application can determine whether to use the default icon.

belongsTo11+

belongsTo(type: string): boolean

Checks whether this data type belongs to the specified uniform data type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Parameters

Name Type Mandatory Description
type string Yes Uniform data type to specify, which is a value of UniformDataType.

Return value

Type Description
boolean Returns true if this data type belongs to or is the same as the specified uniform data type; returns false if they are not related.

Example

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';

try{
    let typeObj : uniformTypeDescriptor.TypeDescriptor = uniformTypeDescriptor.getTypeDescriptor('general.type-script');
    let ret = typeObj.belongsTo('general.plain-text');
    if(ret) {
        console.info('type general.type-script belongs to type general.plain-text');
    }
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`belongsTo throws an exception. code is ${error.code}, message is ${error.message} `);
}

isLowerLevelType11+

isLowerLevelType(type: string): boolean

Checks whether this data type is a lower-level type of the specified uniform data type. For example, TYPE_SCRIPT is a lower-level type of SOURCE_CODE, and TYPE_SCRIPT and SOURCE_CODE are lower-level types of PLAIN_TEXT.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Parameters

Name Type Mandatory Description
type string Yes Uniform data type to specify, which is a value of UniformDataType.

Return value

Type Description
boolean Returns true if this data type is a lower-level type of the specified uniform data type; returns false otherwise.

Example

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';

try{
    let typeObj : uniformTypeDescriptor.TypeDescriptor = uniformTypeDescriptor.getTypeDescriptor('general.type-script');
    let ret = typeObj.isLowerLevelType('general.plain-text');
    if(ret) {
        console.info('type general.type-script is lower level type of type general.plain-text');
    }
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`isLowerLevelType throws an exception. code is ${error.code}, message is ${error.message} `);
}

isHigherLevelType11+

isHigherLevelType(type: string): boolean

Checks whether this data type is a higher-level type of the specified uniform data type. For example, SOURCE_CODE is a higher-level type of TYPE_SCRIPT, and PLAIN_TEXT is a higher-level type of SOURCE_CODE and TYPE_SCRIPT.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Parameters

Name Type Mandatory Description
type string Yes Uniform data type to specify, which is a value of UniformDataType.

Return value

Type Description
boolean Returns true if this data type is a higher-level type of the specified uniform data type; returns false otherwise.

Example

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';

try{
    let typeObj : uniformTypeDescriptor.TypeDescriptor = uniformTypeDescriptor.getTypeDescriptor('general.plain-text');
    let ret = typeObj.isHigherLevelType('general.type-script');
    if(ret) {
        console.info('type general.plain-text is higher level type of type general.type-script');
    }
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`isHigherLevelType throws an exception. code is ${error.code}, message is ${error.message} `);
}

equals11+

equals(typeDescriptor: TypeDescriptor): boolean

Checks whether this data type is the same as the specified uniform data type. That is, compares typeIds of two TypeDescriptor objects.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Parameters

Name Type Mandatory Description
typeDescriptor TypeDescriptor Yes Uniform data type to compare.

Return value

Type Description
boolean Returns true if the type IDs are the same; returns false otherwise.

Example

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';

try{
    let typeA : uniformTypeDescriptor.TypeDescriptor = uniformTypeDescriptor.getTypeDescriptor('general.type-script');
    let typeB : uniformTypeDescriptor.TypeDescriptor = uniformTypeDescriptor.getTypeDescriptor('general.python-script');
    if(!typeA.equals(typeB)) {
      console.info('typeA is not equal to typeB');
    }
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`throws an exception. code is ${error.code}, message is ${error.message} `);
}

uniformTypeDescriptor.getTypeDescriptor11+

getTypeDescriptor(typeId: string): TypeDescriptor

Obtains the TypeDescriptor object based on the uniform data type ID.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Parameters

Name Type Mandatory Description
typeId string Yes ID of the uniform data type.

Return value

Type Description
TypeDescriptor Returns the TypeDescriptor object obtained. If the uniform data type does not exist, null is returned.

Example

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';

try {
    let typeObj : uniformTypeDescriptor.TypeDescriptor = uniformTypeDescriptor.getTypeDescriptor('com.adobe.photoshop-image');
    if (typeObj) {
        let typeId = typeObj.typeId;
        let belongingToTypes = typeObj.belongingToTypes;
        let description = typeObj.description;
        let referenceURL = typeObj.referenceURL;
        let iconFile = typeObj.iconFile;
        console.info(`typeId: ${typeId}, belongingToTypes: ${belongingToTypes}, description: ${description}, referenceURL: ${referenceURL}, iconFile: ${iconFile}`);
    } else {
        console.info('type com.adobe.photoshop-image does not exist');
    }
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`getTypeDescriptor throws an exception. code is ${error.code}, message is ${error.message} `);
}

uniformTypeDescriptor.getUniformDataTypeByFilenameExtension11+

getUniformDataTypeByFilenameExtension(filenameExtension: string, belongsTo?: string): string

Obtains the uniform data type ID based on the given file name extension and data type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Parameters

Name Type Mandatory Description
filenameExtension string Yes File name extension.
belongsTo string No ID of the uniform data type to which the target data type belongs. If this parameter is not specified, the uniform data type ID is queried based on the file name extension.

Return value

Type Description
string Returns the uniform data type ID obtained, or null if no match is found.

Example

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';

try {
    let typeId = uniformTypeDescriptor.getUniformDataTypeByFilenameExtension('.ts', 'general.plain-text');
    if(typeId) {
        console.info('typeId is general.type-script');
    }
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`getUniformDataTypeByFilenameExtension throws an exception. code is ${error.code}, message is ${error.message} `);
}

uniformTypeDescriptor.getUniformDataTypeByMIMEType11+

getUniformDataTypeByMIMEType(mimeType: string, belongsTo?: string): string

Obtains the uniform data type ID based on the given MIME type and data type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Parameters

Name Type Mandatory Description
mimeType string Yes MIME type.
belongsTo string No ID of the uniform data type to which the target data type belongs. If this parameter is not specified, the uniform data type ID is queried based on the MIME type.

Return value

Type Description
string Returns the uniform data type ID obtained, or null if no match is found.

Example

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';

try {
    let typeId = uniformTypeDescriptor.getUniformDataTypeByMIMEType('image/jpeg', 'general.image');
    if(typeId) {
        console.info('typeId is general.jpeg');
    }
} catch(e) {
    let error: BusinessError = e as BusinessError;
    console.error(`getUniformDataTypeByMIMEType throws an exception. code is ${error.code}, message is ${error.message} `);
}