OpenHarmony应用开发-FA模型切换Stage模型指导-API切换

素年锦时静待君丶
发布于 2023-4-11 16:42
浏览
0收藏

版本:v3.2 Beta5

API切换概述

FA模型和Stage模型由于线程模型和进程模型的差异,部分接口仅在FA模型下才能使用,针对这部分接口在SDK的接口中有FAModelOnly的标记,用于提醒开发者这部分接口仅能在FA模型下使用。因此在切换到Stage模型时,需要将应用中用到的FAModelOnly接口替换成Stage模型下对应的接口。下面是startAbility的接口切换示例,全量接口列表请查看后续章节:

OpenHarmony应用开发-FA模型切换Stage模型指导-API切换-鸿蒙开发者社区

startAbility接口由FA模型切换到Stage模型的示例:

  • FA模型示例

import fa from '@ohos.ability.featureAbility';
let parameter = {
  "want": {
    bundleName: "ohos.samples.demo",
    abilityName: "ohos.samples.demo.MainAbility"
  }
}
fa.startAbility(parameter).then((data) => {
  console.info('startAbility success');
}).catch((error) => {
  console.error('startAbility failed.');
})
  • Stage示例示例

// context为Ability对象的成员,在非Ability对象内部调用需要
// 将Context对象传递过去
let wantInfo = {
  bundleName: "ohos.samples.demo",
  abilityName: "ohos.samples.demo.MainAbility"
};
this.context.startAbility(wantInfo).then((data) => {
  console.info('startAbility success.');
}).catch((error) => {
  console.error('startAbility failed.');
})

Context接口切换

FA接口

Stage模型接口对应d.ts文件

Stage对应接口或字段

​getOrCreateLocalDir(callback:AsyncCallback<string>):void;​​​​getOrCreateLocalDir():Promise<string>;​

Stage模型无对应接口

Stage模型应用在应用根目录下没有操作权限,不提供对应接口

​verifyPermission(permission:string,options:PermissionOptions,callback:AsyncCallback<number>):void;​​​​verifyPermission(permission:string,callback:AsyncCallback<number>):void;​

​verifyPermission(permission:string,options?:PermissionOptions):Promise<number>;​

@ohos.abilityAccessCtrl.d.ts

​verifyAccessTokenSync(tokenID: number, permissionName: Permissions): GrantStatus;​​​​verifyAccessToken(tokenID: number, permissionName: Permissions): Promise<GrantStatus>;​

​requestPermissionsFromUser(permissions:Array<string>,requestCode:number,resultCallback:AsyncCallback<PermissionRequestResult>):void;​​​​requestPermissionsFromUser(permissions:Array<string>,requestCode:number):Promise<PermissionRequestResult>;​

application\UIAbilityContext.d.ts

​requestPermissionsFromUser(permissions: Array<string>, requestCallback: AsyncCallback<PermissionRequestResult>) : void;​​​​requestPermissionsFromUser(permissions: Array<string>) : Promise<PermissionRequestResult>;​

​getApplicationInfo(callback:AsyncCallback<ApplicationInfo>):void;​​​​getApplicationInfo():Promise<ApplicationInfo>;​

application\Context.d.ts

​applicationInfo: ApplicationInfo;​

​getBundleName(callback : AsyncCallback<string>): void;​​​​getBundleName(): Promise<string>;​

application\UIAbilityContext.d.ts

​abilityInfo.bundleName: string;​

​getDisplayOrientation(callback : AsyncCallback<bundle.DisplayOrientation>): void;​​​​getDisplayOrientation(): Promise<bundle.DisplayOrientation>;​

@ohos.screen.d.ts

​readonly orientation: Orientation;​

​setDisplayOrientation(orientation:bundle.DisplayOrientation, callback:AsyncCallback<void>):void;​​​​setDisplayOrientation(orientation:bundle.DisplayOrientation):Promise<void>;​

@ohos.screen.d.ts

​setOrientation(orientation: Orientation, callback: AsyncCallback<void>): void;​​​​setOrientation(orientation: Orientation): Promise<void>;​

​setShowOnLockScreen(show:boolean, callback:AsyncCallback<void>):void;​​​​setShowOnLockScreen(show:boolean):Promise<void>;​

@ohos.window.d.ts

​setShowOnLockScreen(showOnLockScreen: boolean): void;​

​setWakeUpScreen(wakeUp:boolean, callback:AsyncCallback<void>):void;​​​​setWakeUpScreen(wakeUp:boolean):Promise<void>;​

@ohos.window.d.ts

​setWakeUpScreen(wakeUp: boolean): void;​

​getProcessInfo(callback:AsyncCallback<ProcessInfo>):void;​​​​getProcessInfo():Promise<ProcessInfo>;​

@ohos.app.ability.abilityManager.d.ts

​getAbilityRunningInfos(callback: AsyncCallback<Array<AbilityRunningInfo>>): void;​​​​getAbilityRunningInfos(): Promise<Array<AbilityRunningInfo>>;​

​getElementName(callback:AsyncCallback<ElementName>):void;​​​​getElementName():Promise<ElementName>;​

application\UIAbilityContext.d.ts

​abilityInfo.name: string;​​​​abilityInfo.bundleName: string;​

​getProcessName(callback:AsyncCallback<string>):void;​​​​getProcessName():Promise<string>;​

@ohos.app.ability.abilityManager.d.ts

​getAbilityRunningInfos(callback: AsyncCallback<Array<AbilityRunningInfo>>): void;​​​​getAbilityRunningInfos(): Promise<Array<AbilityRunningInfo>>;​

​getCallingBundle(callback:AsyncCallback<string>):void;​​​​getCallingBundle():Promise<string>;​

Stage模型无对应接口

Stage模型应用可以使用Want.parameters的ohos.aafwk.param.callerUid参数,获取调用方的应用信息

​getFilesDir(callback:AsyncCallback<string>):void;​​​​getFilesDir():Promise<string>;​

application\Context.d.ts

​filesDir: string;​

​getCacheDir(callback:AsyncCallback<string>):void;​​​​getCacheDir():Promise<string>;​

application\Context.d.ts

​cacheDir: string;​

​getOrCreateDistributedDir(callback:AsyncCallback<string>):void;​​​​getOrCreateDistributedDir():Promise<string>;​

application\Context.d.ts

​distributedFilesDir: string;​

​getAppType(callback:AsyncCallback<string>):void;​​​​getAppType():Promise<string>;​

application\UIAbilityContext.d.ts

通过abilityInfo字段的type属性获取

​abilityInfo.type: bundleManager.AbilityType;​

​getHapModuleInfo(callback:AsyncCallback<HapModuleInfo>):void;​​​​getHapModuleInfo():Promise<HapModuleInfo>;​

application\UIAbilityContext.d.ts

​currentHapModuleInfo: HapModuleInfo;​

​getAppVersionInfo(callback:AsyncCallback<AppVersionInfo>):void;​​​​getAppVersionInfo():Promise<AppVersionInfo>;​

bundle\bundleInfo.d.ts

​readonly name: string;​​​​readonly versionCode: number;​

​readonly versionName: string;​

​getApplicationContext():Context;​

application\Context.d.ts

​getApplicationContext(): ApplicationContext;​

​getAbilityInfo(callback:AsyncCallback<AbilityInfo>):void;​​​​getAbilityInfo():Promise<AbilityInfo>;​

application\UIAbilityContext.d.ts

​abilityInfo: AbilityInfo;​

​isUpdatingConfigurations(callback:AsyncCallback<boolean>):void;​​​​isUpdatingConfigurations():Promise<boolean>;​

Stage模型无对应接口

OpenHarmony在系统环境变化时,应用不会重启,调用onConfigurationUpdated接口通知应用,该接口在FA模型是空实现接口,Stage模型不提供对应接口

​printDrawnCompleted(callback:AsyncCallback<void>):void;​​​​printDrawnCompleted():Promise<void>;​

featureAbility接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

​getWant(callback: AsyncCallback<Want>): void;​​​​getWant(): Promise<Want>;​

@ohos.app.ability.UIAbility.d.ts

​launchWant: Want;​

​startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>): void;​​​​startAbility(parameter: StartAbilityParameter): Promise<number>;​

application\UIAbilityContext.d.ts

​startAbility(want: Want, callback: AsyncCallback<void>): void;​​​​startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;​

​startAbility(want: Want, options?: StartOptions): Promise<void>;​

​getContext(): Context;​

@ohos.app.ability.UIAbility.d.ts

​context: UIAbilityContext;​

​startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback<AbilityResult>): void;​​​​startAbilityForResult(parameter: StartAbilityParameter): Promise<AbilityResult>;​

application\UIAbilityContext.d.ts

​startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void;​​​​startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void;​

​startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>;​

​terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;​​​​terminateSelfWithResult(parameter: AbilityResult): Promise<void>;​

application\UIAbilityContext.d.ts

​terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;​​​​terminateSelfWithResult(parameter: AbilityResult): Promise<void>;​

​terminateSelf(callback: AsyncCallback<void>): void;​​​​terminateSelf(): Promise<void>;​

application\UIAbilityContext.d.ts

​terminateSelf(callback: AsyncCallback<void>): void;​​​​terminateSelf(): Promise<void>;​

​acquireDataAbilityHelper(uri: string): DataAbilityHelper;​

@ohos.data.dataShare.d.ts

@ohos.data.fileAccess.d.ts

​createDataShareHelper(context: Context, uri: string, callback: AsyncCallback<DataShareHelper>): void;​​​​createDataShareHelper(context: Context, uri: string): Promise<DataShareHelper>;​

​createFileAccessHelper(context: Context): FileAccessHelper;​

​createFileAccessHelper(context: Context, wants: Array<Want>): FileAccessHelper;​

​hasWindowFocus(callback: AsyncCallback<boolean>): void;​​​​hasWindowFocus(): Promise<boolean>;​

@ohos.window.d.ts

​on(eventType: ‘windowStageEvent’, callback: Callback<WindowStageEventType>): void;​​​监听​​Active​​获焦状态

​connectAbility(request: Want, options:ConnectOptions ): number;​

application\UIAbilityContext.d.ts

​connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;​

​disconnectAbility(connection: number, callback:AsyncCallback<void>): void;​​​​disconnectAbility(connection: number): Promise<void>;​

application\UIAbilityContext.d.ts

​disconnectAbility(connection: number, callback:AsyncCallback<void>): void;​​​​disconnectAbility(connection: number): Promise<void>;​

​getWindow(callback: AsyncCallback<window.Window>): void;​​​​getWindow(): Promise<window.Window>;​

@ohos.window.d.ts

​getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void;​​​​getLastWindow(ctx: BaseContext): Promise<Window>;​

particleAbility接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

​startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<number>): void;​​​​startAbility(parameter: StartAbilityParameter): Promise<number>;​

application\ServiceExtensionContext.d.ts

​startAbility(want: Want, callback: AsyncCallback<void>): void;​​​​startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;​

​startAbility(want: Want, options?: StartOptions): Promise<void>;​

​startServiceExtensionAbility(want: Want, callback: AsyncCallback<void>): void;​

​startServiceExtensionAbility(want: Want): Promise<void>;​

​terminateSelf(callback: AsyncCallback<void>): void;​​​​terminateSelf(): Promise<void>;​

application\ServiceExtensionContext.d.ts

​terminateSelf(callback: AsyncCallback<void>): void;​​​​terminateSelf(): Promise<void>;​

​connectAbility(request: Want, options:ConnectOptions ): number;​

application\ServiceExtensionContext.d.ts

​connectAbility(want: Want, options: ConnectOptions): number;​​​​connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;​

​disconnectAbility(connection: number, callback:AsyncCallback<void>): void;​​​​disconnectAbility(connection: number): Promise<void>;​

application\ServiceExtensionContext.d.ts

​disconnectAbility(connection: number, callback:AsyncCallback<void>): void; ​​​​disconnectAbility(connection: number): Promise<void>;​

​disconnectServiceExtensionAbility(connection: number, callback: AsyncCallback<void>): void;​

​disconnectServiceExtensionAbility(connection: number): Promise<void>;​

​acquireDataAbilityHelper(uri: string): DataAbilityHelper;​

@ohos.data.dataShare.d.ts

[@ohos.data.fileAccess.d.ts

​createDataShareHelper(context: Context, uri: string, callback: AsyncCallback<DataShareHelper>): void;​​​​createDataShareHelper(context: Context, uri: string): Promise<DataShareHelper>;​

​createFileAccessHelper(context: Context): FileAccessHelper;​

​createFileAccessHelper(context: Context, wants: Array<Want>): FileAccessHelper;​

​startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback<void>): void;​​​​startBackgroundRunning(id: number, request: NotificationRequest): Promise<void>;​

@ohos.resourceschedule.backgroundTaskManager.d.ts

​startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback): void;​​​​startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise<void>;​

​cancelBackgroundRunning(callback: AsyncCallback<void>): void;​​​​cancelBackgroundRunning(): Promise<void>;​

@ohos.resourceschedule.backgroundTaskManager.d.ts

​stopBackgroundRunning(context: Context, callback: AsyncCallback): void;​​​​stopBackgroundRunning(context: Context): Promise<void>;​

LifecycleForm接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

onCreate?(want: Want): formBindingData.FormBindingData;

@ohos.app.form.FormExtensionAbility.d.ts

​onAddForm(want: Want): formBindingData.FormBindingData;​

onCastToNormal?(formId: string): void;

@ohos.app.form.FormExtensionAbility.d.ts

​onCastToNormalForm(formId: string): void;​

onUpdate?(formId: string): void;

@ohos.app.form.FormExtensionAbility.d.ts

​onUpdateForm(formId: string): void;​

onVisibilityChange?(newStatus: { [key: string]: number }): void;

@ohos.app.form.FormExtensionAbility.d.ts

​onChangeFormVisibility(newStatus: { [key: string]: number }): void;​

onEvent?(formId: string, message: string): void;

@ohos.app.form.FormExtensionAbility.d.ts

​onFormEvent(formId: string, message: string): void;​

onDestroy?(formId: string): void;

@ohos.app.form.FormExtensionAbility.d.ts

​onRemoveForm(formId: string): void;​

onAcquireFormState?(want: Want): formInfo.FormState;

@ohos.app.form.FormExtensionAbility.d.ts

​onAcquireFormState?(want: Want): formInfo.FormState;​

onShare?(formId: string): {[key: string]: any};

@ohos.app.form.FormExtensionAbility.d.ts

​onShareForm?(formId: string): { [key: string]: any };​

LifecycleApp接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

onShow?(): void;

@ohos.window.d.ts

​on(eventType: ‘windowStageEvent’, callback: Callback<WindowStageEventType>): void;​​​监听​​FOREGROUND​​切到前台状态

onHide?(): void;

@ohos.window.d.ts

​on(eventType: ‘windowStageEvent’, callback: Callback<WindowStageEventType>): void;​​​监听​​BACKGROUND​​切到后台状态

onDestroy?(): void;

@ohos.app.ability.UIAbility.d.ts

​onDestroy(): void;​

onCreate?(): void;

@ohos.app.ability.UIAbility.d.ts

​onCreate(want: Want, param: AbilityConstant.LaunchParam): void;​

onWindowDisplayModeChanged?(isShownInMultiWindow: boolean, newConfig: resourceManager.Configuration): void;

Stage模型无对应接口

暂时未提供对应接口

onStartContinuation?(): boolean;

Stage模型无对应接口

Stage模型上,应用无需感知迁移是否成功(由应用发起迁移请求时感知),onStartContinuation废弃

onSaveData?(data: Object): boolean;

@ohos.app.ability.UIAbility.d.ts

​onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;​

onCompleteContinuation?(result: number): void;

application\ContinueCallback.d.ts

​onContinueDone(result: number): void;​

onRestoreData?(data: Object): void;

@ohos.app.ability.UIAbility.d.ts

​onCreate(want: Want, param: AbilityConstant.LaunchParam): void;​​​​onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;​

标准实例模式Ability迁移目标端在onCreate回调中完成数据恢复,单实例应用迁移目标端在onCreate回调中完成数据恢复,回调中通过判断launchParam.launchReason可获取迁移启动的场景,从而可以从Want中获取迁移前保存的数据

onRemoteTerminated?(): void;

application\ContinueCallback.d.ts

​onContinueDone(result: number): void;​

onSaveAbilityState?(outState: PacMap): void;

@ohos.app.ability.UIAbility.d.ts

​onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any}): AbilityConstant.OnSaveResult;​

onRestoreAbilityState?(inState: PacMap): void;

@ohos.app.ability.UIAbility.d.ts

​onCreate(want: Want, param: AbilityConstant.LaunchParam): void;​​应用重启后会触发Ability的onCreate方法,通过判断launchParam.launchReason可获取自恢复的场景,从而可以从Want中获取重启前保存的数据

onInactive?(): void;

@ohos.app.ability.UIAbility.d.ts

​onBackground(): void;​

onActive?(): void;

@ohos.app.ability.UIAbility.d.ts

​onForeground(): void;​

onNewWant?(want: Want): void;

@ohos.app.ability.UIAbility.d.ts

​onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;​

onMemoryLevel?(level: number): void

@ohos.app.ability.UIAbility.d.ts

​onMemoryLevel(level: AbilityConstant.MemoryLevel): void;​

LifecycleService接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

onStart?(): void;

@ohos.app.ability.ServiceExtensionAbility.d.ts

​onCreate(want: Want): void;​

onCommand?(want: Want, startId: number): void;

@ohos.app.ability.ServiceExtensionAbility.d.ts

​onRequest(want: Want, startId: number): void;​

onStop?(): void;

@ohos.app.ability.ServiceExtensionAbility.d.ts

​onDestroy(): void;​

onConnect?(want: Want): rpc.RemoteObject;

@ohos.app.ability.ServiceExtensionAbility.d.ts

​onConnect(want: Want): rpc.RemoteObject;​

onDisconnect?(want: Want): void;

@ohos.app.ability.ServiceExtensionAbility.d.ts

​onDisconnect(want: Want): void;​

onReconnect?(want: Want): void;

@ohos.app.ability.ServiceExtensionAbility.d.ts

​onReconnect(want: Want): void;​

LifecycleData接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;

@ohos.application.DataShareExtensionAbility.d.ts

​update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback<number>): void;​

query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;

@ohos.application.DataShareExtensionAbility.d.ts

​query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>): void;​

delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;

@ohos.application.DataShareExtensionAbility.d.ts

​delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>): void;​

normalizeUri?(uri: string, callback: AsyncCallback<string>): void;

@ohos.application.DataShareExtensionAbility.d.ts

​normalizeUri?(uri: string, callback: AsyncCallback<string>): void;​

batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void;

@ohos.application.DataShareExtensionAbility.d.ts

​batchInsert?(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>): void;​

denormalizeUri?(uri: string, callback: AsyncCallback<string>): void;

@ohos.application.DataShareExtensionAbility.d.ts

​denormalizeUri?(uri: string, callback: AsyncCallback<string>): void;​

insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;

@ohos.application.DataShareExtensionAbility.d.ts

​insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>): void;​

openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void;

Stage模型无对应接口

Stage模型不支持uri跨进程访问,建议通过​​want携带fd和文件信息​​进行跨进程文件访问

getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void;

Stage模型无对应接口

Stage模型不支持uri跨进程访问,建议通过​​want携带fd和文件信息​​进行跨进程文件访问

onInitialized?(info: AbilityInfo): void;

@ohos.application.DataShareExtensionAbility.d.ts

​onCreate?(want: Want, callback: AsyncCallback<void>): void;​

getType?(uri: string, callback: AsyncCallback<string>): void;

Stage模型无对应接口

Stage模型不支持uri跨进程访问,建议通过​​want携带fd和文件信息​​进行跨进程文件访问

executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void;

Stage模型无对应接口

暂时未提供对应接口

call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void;

Stage模型无对应接口

暂时未提供对应接口

DataAbilityHelper接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

​openFile(uri: string, mode: string, callback: AsyncCallback<number>): void;​​​​openFile(uri: string, mode: string): Promise<number>;​

@ohos.data.fileAccess.d.ts

​openFile(uri: string, flags: OPENFLAGS) : Promise<number>;​​​​openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback<number>) : void;​

​on(type: ‘dataChange’, uri: string, callback: AsyncCallback<void>): void;​

@ohos.data.dataShare.d.ts

​on(type: ‘dataChange’, uri: string, callback: AsyncCallback<void>): void;​

​off(type: ‘dataChange’, uri: string, callback?: AsyncCallback<void>): void;​

@ohos.data.dataShare.d.ts

​off(type: ‘dataChange’, uri: string, callback?: AsyncCallback<void>): void;​

​getType(uri: string, callback: AsyncCallback<string>): void;​​​​getType(uri: string): Promise<string>;​

Stage模型无对应接口

Stage模型不支持uri跨进程访问,建议通过​​want携带fd和文件信息​​进行跨进程文件访问

​getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void;​​​​getFileTypes(uri: string, mimeTypeFilter: string): Promise<Array<string>>;​

Stage模型无对应接口

Stage模型不支持uri跨进程访问,建议通过​​want携带fd和文件信息​​进行跨进程文件访问

​normalizeUri(uri: string, callback: AsyncCallback<string>): void;​​​​normalizeUri(uri: string): Promise<string>;​

@ohos.data.dataShare.d.ts

​normalizeUri(uri: string, callback: AsyncCallback<string>): void;​​​​normalizeUri(uri: string): Promise<string>;​

​denormalizeUri(uri: string, callback: AsyncCallback<string>): void;​​​​denormalizeUri(uri: string): Promise<string>;​

@ohos.data.dataShare.d.ts

​denormalizeUri(uri: string, callback: AsyncCallback<string>): void;​​​​denormalizeUri(uri: string): Promise<string>;​

​notifyChange(uri: string, callback: AsyncCallback<void>): void;​​​​notifyChange(uri: string): Promise<void>;​

@ohos.data.dataShare.d.ts

​notifyChange(uri: string, callback: AsyncCallback<void>): void;​​​​notifyChange(uri: string): Promise<void>;​

​insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;​​​​insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise<number>;​

@ohos.data.dataShare.d.ts

​insert(uri: string, value: ValuesBucket, callback: AsyncCallback<number>): void;​​​​insert(uri: string, value: ValuesBucket): Promise<number>;​

​batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void;​​​​batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise<number>;​

@ohos.data.dataShare.d.ts

​batchInsert(uri: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>): void;​​​​batchInsert(uri: string, values: Array<ValuesBucket>): Promise<number>;​

​delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;​​​​delete(uri: string, predicates?: dataAbility.DataAbilityPredicates): Promise<number>;​

​delete(uri: string, callback: AsyncCallback<number>): void;​

@ohos.data.dataShare.d.ts

​delete(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>): void;​​​​delete(uri: string, predicates: dataSharePredicates.DataSharePredicates): Promise<number>;​

​update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;​​​​update(uri: string, valuesBucket: rdb.ValuesBucket, predicates?: dataAbility.DataAbilityPredicates): Promise<number>;​

​update(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;​

@ohos.data.dataShare.d.ts

​update(uri: string, predicates: dataSharePredicates.DataSharePredicates, value: ValuesBucket, callback: AsyncCallback<number>): void;​​​​update(uri: string, predicates: dataSharePredicates.DataSharePredicates, value: ValuesBucket): Promise<number>;​

​query(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;​​​​query(uri: string, callback: AsyncCallback<ResultSet>): void;​

​query(uri: string, columns: Array<string>, callback: AsyncCallback<ResultSet>): void;​

​query(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;​

​query(uri: string, columns?: Array<string>, predicates?: dataAbility.DataAbilityPredicates): Promise<ResultSet>;​

@ohos.data.dataShare.d.ts

​query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<DataShareResultSet>): void;​​​​query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>): Promise<DataShareResultSet>;​

​call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void;​​​​call(uri: string, method: string, arg: string, extras: PacMap): Promise<PacMap>;​

Stage模型无对应接口

暂时未提供对应接口

​executeBatch(uri: string, operations: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void;​​​​executeBatch(uri: string, operations: Array<DataAbilityOperation>): Promise<Array<DataAbilityResult>>;​

Stage模型无对应接口

暂时未提供对应接口

mediaLibrary接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

​getMediaLibrary(): MediaLibrary;​

@ohos.multimedia.mediaLibrary.d.ts

​getMediaLibrary(context: Context): MediaLibrary;​

request接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

​download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;​​​​download(config: DownloadConfig): Promise<DownloadTask>;​

@ohos.request.d.ts

​downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;​​​​downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;​

​upload(config: UploadConfig, callback: AsyncCallback<UploadTask>): void;​​​​upload(config: UploadConfig): Promise<UploadTask>;​

@ohos.request.d.ts

​uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;​​​​uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>;​

resourceManager接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应字段

​getResourceManager(callback: AsyncCallback<ResourceManager>): void;​​​​getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void;​

​getResourceManager(): Promise<ResourceManager>;​

​getResourceManager(bundleName: string): Promise<ResourceManager>;​

application\Context.d.ts

​resourceManager: resmgr.ResourceManager;​

window接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

​enum WindowType {
TYPE_APP
}​

@ohos.window.d.ts

​createSubWindow(name: string, callback: AsyncCallback<Window>): void;​​​​createSubWindow(name: string): Promise;​

FA模型应用通过window.create(id, WindowType.TYPE_APP)接口创建应用子窗口,Stage模型应用可使用WindowStage.CreateSubWindow()接口代替

​create(id: string, type: WindowType, callback: AsyncCallback<Window>): void;​​​​create(id: string, type: WindowType): Promise<Window>;​

@ohos.window.d.ts

​createWindow(config: Configuration, callback: AsyncCallback<Window>): void;​​​​createWindow(config: Configuration): Promise<Window>;​

​getTopWindow(callback: AsyncCallback<Window>): void;​​​​getTopWindow(): Promise<Window>;​

@ohos.window.d.ts

​getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void;​​​​getLastWindow(ctx: BaseContext): Promise<Window>;​

Storage接口切换

FA模型接口

Stage模型接口对应d.ts文件

Stage模型对应接口

GetStorageOptions

Stage模型无对应接口

Storage接口功能使用Prefereces接口来代替,接口入参已经重新设计

SetStorageOptions

Stage模型无对应接口

Storage接口功能使用Prefereces接口来代替,接口入参已经重新设计

ClearStorageOptions

Stage模型无对应接口

Storage接口功能使用Prefereces接口来代替,接口入参已经重新设计

DeleteStorageOptions

Stage模型无对应接口

Storage接口功能使用Prefereces接口来代替,接口入参已经重新设计

​static get(options: GetStorageOptions): void;​

@ohos.data.preferences.d.ts

​get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): void;​​​​get(key: string, defValue: ValueType): Promise<ValueType>;​

​static set(options: SetStorageOptions): void;​

@ohos.data.preferences.d.ts

​put(key: string, value: ValueType, callback: AsyncCallback<void>): void;​​​​put(key: string, value: ValueType): Promise<void>;​

​static clear(options?: ClearStorageOptions): void;​

@ohos.data.preferences.d.ts

​clear(callback: AsyncCallback<void>): void;​​​​clear(): Promise<void>;​

​static delete(options: DeleteStorageOptions): void;​

@ohos.data.preferences.d.ts

​delete(key: string, callback: AsyncCallback<void>): void;​​​​delete(key: string): Promise<void>;​




文章转载自:​​https://docs.openharmony.cn/pages/v3.2Beta/zh-cn/application-dev/application-models/storage-switch.md/​

已于2023-4-11 16:42:23修改
收藏
回复
举报
回复
    相关推荐