@ohos.file.cloudDiskManager (云盘管理)(系统接口)
本模块是为系统文件管理应用提供获取三方网盘注册的同步根信息的能力。
说明:
本模块首批接口从API version 21开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
导入模块
import { cloudDiskManager } from '@kit.CoreFileKit';
SyncFolderAccessor
同步根管理类,负责为系统文件管理应用提供获取三方网盘注册的同步根信息的能力。
constructor
constructor()
SyncFolderAccessor的构造函数,用于获取SyncFolderAccessor类的实例。
系统接口:此接口为系统接口。
系统能力:SystemCapability.FileManagement.CloudDiskManager
需要权限:ohos.permission.ACCESS_CLOUD_DISK_INFO
错误码:
接口抛出错误码的详细介绍请参见通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
build() {
Column() {
Button('constructor')
.onClick(async() => {
try {
let syncFolderAccessor: cloudDiskManager.SyncFolderAccessor = new cloudDiskManager.SyncFolderAccessor();
} catch (err) {
let error: BusinessError = err as BusinessError;
console.error(`SyncFolderAccessor constructor failed. Code: ${error.code}, message: ${error.message}`);
}
});
}
}
}
getAllSyncFolders
getAllSyncFolders(): Promise<Array<SyncFolder>>
获取所有注册的同步根信息。使用Promise异步回调。
系统接口:此接口为系统接口。
系统能力:SystemCapability.FileManagement.CloudDiskManager
需要权限:ohos.permission.ACCESS_CLOUD_DISK_INFO
返回值:
| 类型 | 说明 |
|---|---|
| Promise<Array<SyncFolder>> | Promise对象。返回所有网盘应用的同步根列表。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
| 801 | Device not supported. |
| 34400003 | IPC communication failed. |
| 34400014 | Temporary failure, Retry is recommended (e.g., network issues). |
| 34400015 | Cloud disk is not allowed on this device. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
const TAG: string = '[cloudDiskManager]';
try {
console.info(TAG + `getAllSyncFolders start`);
let syncFolderAccessor: cloudDiskManager.SyncFolderAccessor = new cloudDiskManager.SyncFolderAccessor();
syncFolderAccessor.getAllSyncFolders().then((syncFolders) => {
if (syncFolders) {
console.info(TAG + `getAllSyncFolders success, length: ${syncFolders.length}`);
for (let i = 0; i < syncFolders.length; ++i) {
console.info(TAG + `syncFolders[${i}].path: ${syncFolders[i].path}`);
console.info(TAG + `syncFolders[${i}].bundleName: ${syncFolders[i].bundleName}`);
console.info(TAG + `syncFolders[${i}].state: ${syncFolders[i].state}`);
if (syncFolders[i].displayNameResId) {
console.info(TAG + `syncFolders[${i}].displayNameResId: ${syncFolders[i].displayNameResId}`);
}
if (syncFolders[i].customAlias) {
console.info(TAG + `syncFolders[${i}].customAlias: ${syncFolders[i].customAlias}`);
}
}
} else {
console.info(TAG + `getAllSyncFolders failed`);
}
}).catch((e: BusinessError<object>) => {
console.error(TAG + `getAllSyncFolders then catch err, code: ${e.code}, message: ${e.message}`);
})
} catch (err) {
let error: BusinessError = err as BusinessError;
console.error(TAG + `getAllSyncFolders failed. code: ${error.code}, message: ${error.message}`);
}
SyncFolder
表示同步根信息。
系统接口:此接口为系统接口。
系统能力:SystemCapability.FileManagement.CloudDiskManager
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| path | string | 否 | 否 | 同步根对应的URI。 |
| bundleName | string | 否 | 否 | 同步根对应的包名。 |
| state | SyncFolderState | 否 | 否 | 同步根对应的状态信息。 |
| displayNameResId | number | 否 | 是 | 资源ID,可以映射到文管列表显示的别名。默认值为undefined。 |
| customAlias | string | 否 | 是 | 在文管列表显示的别名。默认值为undefined。 |
SyncFolderState
枚举,云盘的同步根的状态。
系统接口:此接口为系统接口。
系统能力:SystemCapability.FileManagement.CloudDiskManager
| 名称 | 值 | 说明 |
|---|---|---|
| INACTIVE | 0 | 表示同步根处于未激活状态。 |
| ACTIVE | 1 | 表示同步根处于激活状态。 |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 js-apis-file-environment-sys
openharmony 鸿蒙 js-apis-file-fs
openharmony 鸿蒙 capi-clouddisk-clouddisk-pathinfo
openharmony 鸿蒙 capi-clouddisk-clouddisk-changesresult
openharmony 鸿蒙 capi-clouddisk-clouddisk-syncfolder
openharmony 鸿蒙 js-apis-fileShare
openharmony 鸿蒙 js-apis-file-storage-statistics-sys