harmony(鸿蒙)@ohos.environment (Directory Environment Capability)

2022-08-09 浏览 (764)

@ohos.environment (Directory Environment Capability)

The Environment module provides APIs for obtaining the root directories of the storage and public files.

NOTE

  • The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The APIs of this module are system APIs and cannot be called by third-party applications.

Modules to Import

import environment from '@ohos.environment';

environment.getStorageDataDir

getStorageDataDir():Promise<string>

Obtains the root directory of the storage. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.File.Environment

Return value

TypeDescription
Promise<string>Promise returned with the root directory of the storage.

Example

environment.getStorageDataDir().then(function(path){
    console.info("getStorageDataDir successfully:"+ path);
}).catch(function(error){
    console.info("getStorageDataDir failed with error:"+ error);
});

environment.getStorageDataDir

getStorageDataDir(callback:AsyncCallback<string>):void

Obtains the root directory of the storage. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.FileManagement.File.Environment

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<string>YesAsynchronous callback used to return the root directory of the storage.

Example

environment.getStorageDataDir(function(error, path){
    // do something
});

environment.getUserDataDir

getUserDataDir():Promise<string>

Obtains the root directory of public files. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.File.Environment

Return value

TypeDescription
Promise<string>Promise returned with the root directory of public files.

Example

environment.getUserDataDir().then(function(path){
    console.info("getUserDataDir successfully:"+ path);
}).catch(function(error){
    console.info("getUserDataDir failed with error:"+ error);
});

environment.getUserDataDir

getUserDataDir(callback:AsyncCallback<string>): void

Obtains the root directory of public files. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.FileManagement.File.Environment

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<string>YesAsynchronous callback used to return the root directory of public files.

Example

environment.getUserDataDir(function(error, path){
    // do something
});

你可能感兴趣的鸿蒙文章

harmony(鸿蒙)APIs

harmony(鸿蒙)System Common Events

harmony(鸿蒙)System Common Events

harmony(鸿蒙)API Reference Document Description

harmony(鸿蒙)BundleStatusCallback

harmony(鸿蒙)@ohos.bundle.innerBundleManager (innerBundleManager)

harmony(鸿蒙)@ohos.distributedBundle (Distributed Bundle Management)

harmony(鸿蒙)@ohos.bundle (Bundle)

harmony(鸿蒙)@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony(鸿蒙)@ohos.WorkSchedulerExtensionAbility (Work Scheduler Callbacks)

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