harmony 鸿蒙@ohos.file.cloudSyncManager (Device-Cloud Synchronization Management)

2023-06-24 浏览 (577)

@ohos.file.cloudSyncManager (Device-Cloud Synchronization Management)

The cloudSyncManager module provides APIs for managing device-cloud synergy for applications. You can use the APIs to enable or disable device-cloud synergy, change the device-cloud synchronization switch for an application, notify cloud data changes, and clear or retain cloud files when a cloud account exits.

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.
  • The APIs of this module are system APIs and cannot be called by third-party applications.

Modules to Import

import cloudSyncManager from '@ohos.file.cloudSyncManager';

cloudSyncManager.changeAppCloudSwitch

changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void>

Changes the device-cloud file synchronization switch for an application. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
bundleNamestringYesBundle name of the application.
statusbooleanYesState of the cloud-device file synchronization switch to set. The value true means to enable this function; the value false means the opposite.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true).then(() => {
  console.info("changeAppCloudSwitch successfully");
}).catch((err: BusinessError) => {
  console.info("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code);
});

cloudSyncManager.changeAppCloudSwitch

changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void

Changes the device-cloud file synchronization switch for an application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
bundleNamestringYesBundle name of the application.
statusbooleanYesState of the cloud-device file synchronization switch to set. The value true means to enable this function; the value false means the opposite.
callbackAsyncCallback<void>YesCallback invoked to return the result.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true, (err: BusinessError) => {
  if (err) {
    console.info("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code);
  } else {
    console.info("changeAppCloudSwitch successfully");
  }
});

cloudSyncManager.notifyDataChange

notifyDataChange(accountId: string, bundleName: string): Promise<void>

Notifies the cloud and device services of the application data change in the cloud. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
bundleNamestringYesBundle name of the application.

Return value

TypeDescription
Promise<void>Promise used to return the application data change in the cloud.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.notifyDataChange(accountId, bundleName).then(() => {
  console.info("notifyDataChange successfully");
}).catch((err: BusinessError) => {
  console.info("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
});

cloudSyncManager.notifyDataChange

notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void

Notifies the cloud and device services of the application data change in the cloud. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
bundleNamestringYesBundle name of the application.
callbackAsyncCallback<void>YesCallback invoked to return the application data change in the cloud.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.notifyDataChange(accountId, bundleName, (err: BusinessError) => {
  if (err) {
    console.info("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
  } else {
    console.info("notifyDataChange successfully");
  }
});

cloudSyncManager.enableCloud

enableCloud(accountId: string, switches: { [bundleName: string]: boolean }): Promise<void>

Enables device-cloud synergy. This API uses a promise to return the result.

Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
switchesobjectYesWhether to enable the device-cloud synergy feature. bundleName indicates the application bundle name. The switch status is a Boolean value.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
let switches: Record<string, boolean> = {
  'com.example.bundleName1': true,
  'com.example.bundleName2': false
}
cloudSyncManager.enableCloud(accountId, switches).then(() => {
  console.info("enableCloud successfully");
}).catch((err: BusinessError) => {
  console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code);
});

cloudSyncManager.enableCloud

enableCloud(accountId: string, switches: { [bundleName: string]: boolean }, callback: AsyncCallback<void>): void

Enables device-cloud synergy. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
switchesobjectYesWhether to enable the device-cloud synergy feature. bundleName indicates the application bundle name. The switch status is a Boolean value.
callbackAsyncCallback<void>YesCallback invoked to return the result.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
let switches: Record<string, boolean> = {
  'com.example.bundleName1': true,
  'com.example.bundleName2': false
}
cloudSyncManager.enableCloud(accountId, switches, (err: BusinessError) => {
  if (err) {
    console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code);
  } else {
    console.info("enableCloud successfully");
  }
});

cloudSyncManager.disableCloud

disableCloud(accountId: string): Promise<void>

Disables device-cloud synergy. This API uses a promise to return the result.

Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
cloudSyncManager.disableCloud(accountId).then(() => {
  console.info("disableCloud successfully");
}).catch((err: BusinessError) => {
  console.info("disableCloud failed with error message: " + err.message + ", error code: " + err.code);
});

cloudSyncManager.disableCloud

disableCloud(accountId: string, callback: AsyncCallback<void>): void

Disables device-cloud synergy. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
callbackAsyncCallback<void>YesCallback invoked to return the result.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
cloudSyncManager.disableCloud(accountId, (err: BusinessError) => {
  if (err) {
    console.info("disableCloud failed with error message: " + err.message + ", error code: " + err.code);
  } else {
    console.info("disableCloud successfully");
  }
});

Action

Enumerates the actions that can be taken to clear local cloud data.

Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

NameValueDescription
RETAIN_DATA0Clear the cloud identifier but retain the files cached locally.
CLEAR_DATA1Clear the cloud identifier and the files cached locally.

cloudSyncManager.clean

clean(accountId: string, appActions: { [bundleName: string]: Action }): Promise<void>

Clears the cloud data locally. This API uses a promise to return the result.

Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
appActionsobjectYesAction to take. bundleName indicates the application bundle to clear, and Action indicates the action to take.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
let appActions: Record<string, cloudSyncManager.Action> = {
  'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA,
  'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA
};
cloudSyncManager.clean(accountId, appActions).then(() => {
  console.info("clean successfully");
}).catch((err: BusinessError) => {
  console.info("clean failed with error message: " + err.message + ", error code: " + err.code);
});

cloudSyncManager.clean

clean(accountId: string, appActions: { [bundleName: string]: Action }, callback: AsyncCallback<void>): void

Clears the cloud data locally. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER

System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager

Parameters

NameTypeMandatoryDescription
accountIdstringYesAccount ID.
appActionsobjectYesAction to take. bundleName indicates the application bundle to clear, and Action indicates the action to take.
callbackAsyncCallback<void>YesCallback invoked to clear the cloud data locally.

Error codes

For details about the error codes, see File Management Error Codes.

IDError Message
201Permission verification failed.
202The caller is not a system application.
401The input parameter is invalid.

Example

import { BusinessError } from '@ohos.base';
let accountId: string = "testAccount";
  let appActions: Record<string, cloudSyncManager.Action> = {
  'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA,
  'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA
};
cloudSyncManager.clean(accountId, appActions, (err: BusinessError) => {
  if (err) {
    console.info("clean failed with error message: " + err.message + ", error code: " + err.code);
  } else {
    console.info("clean successfully");
  }
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

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

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

harmony 鸿蒙@ohos.bundle (Bundle)

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

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