harmony 鸿蒙@ohos.application.BackupExtensionAbility (BackupExtensionAbility)

2023-10-30 浏览 (522)

@ohos.application.BackupExtensionAbility (BackupExtensionAbility)

The BackupExtensionAbility module provides extended backup and restore capabilities for applications.

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 can be used only in the stage model.

Modules to Import

import BackupExtension from '@ohos.application.BackupExtensionAbility';

BundleVersion

Defines the version information required for data restore. You can determine the application data to be restored based on the version information.

System capability: SystemCapability.FileManagement.StorageService.Backup

NameTypeMandatoryDescription
codenumberYesInternal version number of the application.
namestringYesVersion name of the application.

BackupExtensionAbility

Implements backup and restore for application access data. You can use onBackup and onRestore to implement custom backup and restore operations.

Attributes

System capability: SystemCapability.FileManagement.StorageService.Backup

NameTypeReadableWritableDescription
context11+ExtensionContextYesNoContext of the BackupExtensionAbility. It inherits from Context.

onBackup

onBackup(): void;

Called when data is being backed up. You need to implement extended data backup operations.

System capability: SystemCapability.FileManagement.StorageService.Backup

Example

class BackupExt extends BackupExtension {
  async onBackup() {
    console.log('onBackup');
  }
}

onRestore

onRestore(bundleVersion: BundleVersion): void;

Called when data is being restored. You need to implement extended data restore operations.

System capability: SystemCapability.FileManagement.StorageService.Backup

Parameters

NameTypeMandatoryDescription
bundleVersionBundleVersionYesVersion information of the application data to be restored.

Example

import type { BundleVersion } from '@ohos.application.BackupExtensionAbility';
class BackupExt extends BackupExtension {
  async onRestore(bundleVersion : BundleVersion) {
    console.log(`onRestore ok ${JSON.stringify(bundleVersion)}`);
  }
}

你可能感兴趣的鸿蒙文章

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/155465149dc349bfa737fa57dbc5b891