@ohos.file.cloudSyncManager (Device-Cloud Sync Management) (System API)
The cloudSyncManager module provides APIs for managing device-cloud sync for applications. You can use the APIs to enable or disable device-cloud sync, change the device-cloud sync switch for an application, notify cloud data changes, clear or retain cloud files when a cloud account exits, and perform full download.
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.
- This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.file.cloudSyncManager (Device-Cloud Synchronization Management).
Modules to Import
import { cloudSyncManager } from '@kit.CoreFileKit';
cloudSyncManager.changeAppCloudSwitch
changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void>
Changes the device-cloud file sync switch for an application. This API uses a promise to return the result.
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| bundleName | string | Yes | Bundle name. |
| status | boolean | Yes | State of the cloud-device file sync switch to set. The value true means to enable this function; the value false means the opposite. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true).then(() => {
console.info("changeAppCloudSwitch successfully");
}).catch((err: BusinessError) => {
console.error("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 sync switch for an application. This API uses an asynchronous callback to return the result.
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| bundleName | string | Yes | Bundle name of the application. |
| status | boolean | Yes | State of the cloud-device file sync switch to set. The value true means to enable this function; the value false means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result of changing the device-cloud file sync switch for an application. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true, (err: BusinessError) => {
if (err) {
console.error("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 device-cloud service that the cloud data of a specific application under a specified account has been changed. This API uses a promise to return the result.
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| bundleName | string | Yes | Bundle name. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.notifyDataChange(accountId, bundleName).then(() => {
console.info("notifyDataChange successfully");
}).catch((err: BusinessError) => {
console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
});
cloudSyncManager.notifyDataChange
notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void
Notifies the device-cloud service that the cloud data of a specific application under a specified account has been changed. This API uses an asynchronous callback to return the result.
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| bundleName | string | Yes | Bundle name. |
| callback | AsyncCallback<void> | Yes | Callback used to return the application data change in the cloud. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let accountId: string = "testAccount";
let bundleName: string = "com.example.bundle";
cloudSyncManager.notifyDataChange(accountId, bundleName, (err: BusinessError) => {
if (err) {
console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("notifyDataChange successfully");
}
});
ExtraData11+
Represents the cloud data change information.
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| eventId | string | No | No | Change event ID. |
| extraData | string | No | No | Represents the cloud data change information. |
cloudSyncManager.notifyDataChange11+
notifyDataChange(userId: number, extraData: ExtraData): Promise<void>
Notifies the device-cloud service of the cloud data change information of a specified user. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| userId | number | Yes | User ID. |
| extraData | ExtraData | Yes | Represents the cloud data change information. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 13600001 | IPC error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let userId: number = 100;
let extraData: cloudSyncManager.ExtraData = {eventId: "eventId", extraData: "data"};
cloudSyncManager.notifyDataChange(userId, extraData).then(() => {
console.info("notifyDataChange successfully");
}).catch((err: BusinessError) => {
console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
});
cloudSyncManager.notifyDataChange11+
notifyDataChange(userId: number, extraData: ExtraData, callback: AsyncCallback<void>): void
Notifies the device-cloud service of the cloud data change information of a specified user. This API uses an asynchronous callback to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| userId | number | Yes | User ID. |
| extraData | ExtraData | Yes | Represents the cloud data change information. |
| callback | AsyncCallback<void> | Yes | Callback used to return the application data change in the cloud. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 13600001 | IPC error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let userId: number = 100;
let extraData: cloudSyncManager.ExtraData = {eventId: "eventId", extraData: "data"};
cloudSyncManager.notifyDataChange(userId, extraData, (err: BusinessError) => {
if (err) {
console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("notifyDataChange successfully");
}
});
cloudSyncManager.enableCloud
enableCloud(accountId: string, switches: Record<string, boolean>): Promise<void>
Enables device-cloud sync. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| switches | Record<string, boolean> | Yes | Whether to enable the device-cloud sync feature. The application bundle name is a string. The switch status is a Boolean value. The value true means to enable this function; the value false means the opposite. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
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.error("enableCloud failed with error message: " + err.message + ", error code: " + err.code);
});
cloudSyncManager.enableCloud
enableCloud(accountId: string, switches: Record<string, boolean>, callback: AsyncCallback<void>): void
Enables device-cloud sync. This API uses an asynchronous callback to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| switches | Record<string, boolean> | Yes | Whether to enable the device-cloud sync feature. The application bundle name is a string. The switch status is a Boolean value. The value true means to enable this function; the value false means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result of enabling device-cloud sync. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
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.error("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 sync. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let accountId: string = "testAccount";
cloudSyncManager.disableCloud(accountId).then(() => {
console.info("disableCloud successfully");
}).catch((err: BusinessError) => {
console.error("disableCloud failed with error message: " + err.message + ", error code: " + err.code);
});
cloudSyncManager.disableCloud
disableCloud(accountId: string, callback: AsyncCallback<void>): void
Disables device-cloud sync. This API uses an asynchronous callback to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result of disabling device-cloud sync. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let accountId: string = "testAccount";
cloudSyncManager.disableCloud(accountId, (err: BusinessError) => {
if (err) {
console.error("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
| Name | Value | Description |
|---|---|---|
| RETAIN_DATA | 0 | Clear the cloud identifier but retain the files cached locally. |
| CLEAR_DATA | 1 | Clear the cloud identifier and the files cached locally. |
cloudSyncManager.clean
clean(accountId: string, appActions: Record<string, Action>): Promise<void>
Callback used to clear the cloud data locally. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| appActions | Record<string, Action> | Yes | Action to perform. The bundle name of the application whose data is to be cleared is a string. Action specifies the action to perform. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
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.error("clean failed with error message: " + err.message + ", error code: " + err.code);
});
cloudSyncManager.clean
clean(accountId: string, appActions: Record<string, Action>, callback: AsyncCallback<void>): void
Callback used to clear the cloud data locally. This API uses an asynchronous callback to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| accountId | string | Yes | Account ID. |
| appActions | Record<string, Action> | Yes | Action to perform. The bundle name of the application whose data is to be cleared is a string. Action specifies the action to perform. |
| callback | AsyncCallback<void> | Yes | Callback used to clear the cloud data locally. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
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.error("clean failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("clean successfully");
}
});
DowngradeDownload20+
Full download: provides the capability of downloading cloud data for applications.
It supports the full download of cloud application files.
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
constructor20+
constructor(bundleName: string)
A constructor used to create an instance of the DowngradeDownload class with a specified bundle name.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| bundleName | string | Yes | Bundle name. |
Error codes
For details about the error codes, see File Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
| 13900020 | Invalid argument. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'com.demo.a';
try {
let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
} catch (e) {
let error = e as BusinessError;
console.error(`Failed to create downgrade manager object, error code: ${error.code}, message: ${error.message}`);
}
getCloudFileInfo20+
getCloudFileInfo(): Promise<CloudFileInfo>
Obtains the size and count of files for applications requiring full download, including those stored only locally, only in the cloud, or both locally and in the cloud. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Return value
| Type | Description |
|---|---|
| Promise<CloudFileInfo> | Promise used to return the local and cloud file information. |
Error codes
For details about the error codes, see File Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service. |
| 13900010 | Try again. |
| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName: string = "com.demo.a";
let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
downgradeMgr.getCloudFileInfo().then((fileInfo: cloudSyncManager.CloudFileInfo) => {
console.info("cloud file info: " + JSON.stringify(fileInfo));
}).catch((err: BusinessError) => {
console.error(`Failed to get downgrade info, error message: ${err.message}, error code: ${err.code}`);
});
startDownload20+
startDownload(callback: Callback<DownloadProgress>): Promise<void>
Starts the full download for the specified application's cloud files. This API uses a promise to return the result. This API uses an asynchronous callback to return the result.
Repeated triggering of a full download task will throw an error (22400006).
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<DownloadProgress> | Yes | Callback used to return the download progress. The parameter is DownloadProgress, and the return value is void. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see File Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service. |
| 13900010 | Try again. |
| 13900020 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
| 22400006 | The same task is already in progress. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName: string = "com.demo.a";
let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
let callback = (data: cloudSyncManager.DownloadProgress) => {
console.info(`Downgrade progress: downloadedSize: ${data.downloadedSize}, totalSize: ${data.totalSize}`);
if (data.state == cloudSyncManager.DownloadState.COMPLETED) {
console.info('Downgrade finished.');
} else if (data.state == cloudSyncManager.DownloadState.STOPPED) {
console.info(`Downgrade stopped, reason: ${data.stopReason}.`);
}
};
downgradeMgr.startDownload(callback).then(() => {
console.info("Downgrade started successfully.");
}).catch((err: BusinessError) => {
console.error(`Failed to start downgrade, error message: ${err.message}, error code: ${err.code}`);
});
stopDownload20+
stopDownload(): Promise<void>
Stops the full download task triggered by startDownload. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see File Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
| 202 | Permission verification failed, application which is not a system application uses system API. |
| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service. |
| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName: string = "com.demo.a";
let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
downgradeMgr.startDownload((data: cloudSyncManager.DownloadProgress) => {
console.info(`Downgrade progress: downloadedSize: ${data.downloadedSize}, totalSize: ${data.totalSize}`);
}).then(() => {
console.info("Downgrade started successfully.");
}).catch((err: BusinessError) => {
console.error(`Failed to start downgrade, error message: ${err.message}, error code: ${err.code}`);
});
let needStop = true;
if (needStop) {
downgradeMgr.stopDownload().then(() => {
console.info("Downgrade stopped successfully.");
}).catch((err: BusinessError) => {
console.error(`Failed to stop downgrade, error message: ${err.message}, error code: ${err.code}`);
});
}
LocalFilePresentStatus23+
Specifies a result object that contains the application bundle name and the status information about whether there are files that have not been uploaded to the cloud in the cloud storage space.
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| bundleName | string | No | No | Bundle name. |
| isLocalFilePresent | boolean | No | No | Whether there are local files that have not been synchronized to the cloud in the cloud storage space of the application. The value true indicates that such file exists, and the value false indicates the opposite. |
cloudSyncManager.getBundlesLocalFilePresentStatus23+
getBundlesLocalFilePresentStatus(bundleNames: Array<string>): Promise<Array<LocalFilePresentStatus>>
Obtains the existence status of local files for multiple applications and checks whether there are files that have not been uploaded to the cloud in the cloud storage space. This API uses a promise to return the result.
Required permissions: ohos.permission.CLOUDFILE_SYNC_MANAGER
System API: This is a system API.
System capability: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| bundleNames | Array<string> | Yes | Array of application bundle names to be checked. Each element is the bundle name of an application. |
Return value
| Type | Description |
|---|---|
| Promise<Array<LocalFilePresentStatus>> | Promise used to return an array of objects. Each object in the array contains the bundle name of the application to be checked and the local file existence status. |
Error codes
For details about the error codes, see File Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 13600001 | IPC error. Possible causes: 1. IPC failed or timed out. 2. Failed to load the service. |
| 13900010 | Try again. |
| 13900020 | Invalid argument. Possible causes: 1. Mandatory parameters are left unspecified. 2. The length of the input parameter exceeds the upper limit. 3. The input parameter contains an invalid bundleName. |
| 22400005 | Inner error. Possible causes: 1. Failed to access the database or execute the SQL statement. 2. System error, such as a null pointer, insufficient memory or a JS engine exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let bundles: Array<string> = ['com.example.app1', 'com.example.app2'];
cloudSyncManager.getBundlesLocalFilePresentStatus(bundles).then((results: Array<cloudSyncManager.LocalFilePresentStatus>) => {
results.forEach((item) => {
console.info(`bundle: ${item.bundleName}, hasLocalUncloudedFiles: ${item.isLocalFilePresent}`);
});
}).catch((err: BusinessError) => {
console.error(`getBundlesLocalFilePresentStatus failed, code: ${err.code}, message: ${err.message}`);
});