skills/open-deveco/arkts-deprecated-api-solutions-skills/harmonyos_deprecated_api_solutions

harmonyos_deprecated_api_solutions

SKILL.md

Deprecated API Solutions

This skill provides guidance on migrating from deprecated or discouraged APIs to their modern HarmonyOS equivalents (e.g., moving from global APIs to UIContext based APIs).

Covered APIs

API Deprecated/Legacy Usage Modern Replacement
setOrCreate AppStorage.setOrCreate (Global) LocalStorage or AppStorage with caution, prefer UIContext for context
animateTo Global animateTo(...) this.getUIContext().animateTo(...)
getUIContext N/A The core accessor for scoped APIs
generateRandomSync crypto (Legacy) cryptoFramework
decodeToString string utilities util.TextDecoder
showToast promptAction.showToast (Global) this.getUIContext().getPromptAction().showToast(...)
getHostContext Global context access this.getUIContext().getHostContext()
getContext getContext(this) this.getUIContext().getHostContext() with context parameter
px2vp Global px2vp this.getUIContext().px2vp(...)
getRouter @ohos.router this.getUIContext().getRouter()
back router.back() this.getUIContext().getRouter().back()
pushUrl router.pushUrl() this.getUIContext().getRouter().pushUrl()
matchMediaSync mediaquery.matchMediaSync(condition: string) this.getUIContext().getMediaQuery().matchMediaSync(condition: string)
display.getDefaultDisplay window.getDefaultDisplay() display.getDefaultDisplaySync() from @kit.ArkGraphics
Scroll.onScroll Scroll.onScroll((xOffset, yOffset) => void) Scroll.onScroll((xOffset: number, yOffset: number) => void)
window.getLastWindow Async/await pattern Callback pattern: window.getLastWindow(context, (err, win) => { ... })
setWindowLayoutFullScreen Callback pattern Promise pattern: await win.setWindowLayoutFullScreen(true)
setWindowSystemBarProperties Callback pattern Promise pattern: await win.setWindowSystemBarProperties({...})
getTitleButtonRect Return type window.Rect Return type window.TitleButtonRect
AvoidArea Missing visible property Add visible: false to AvoidArea initialization
WindowMode Removed from API Use boolean flag or custom state instead
this in standalone functions Invalid usage Pass context as parameter: function foo(context: Context)
connect Legacy connection UIAbilityContext.connectServiceExtensionAbility
fileio @ohos.fileio @ohos.file.fs
backgroundTaskManager Old API 9 interfaces @ohos.resourceschedule.backgroundTaskManager (New APIs)
notification @ohos.notification @ohos.notificationManager
http @ohos.net.http @hms.collaboration.rcp (Recommended)
featureAbility FA Model Context UIAbilityContext (Stage Model)
FaultLogger @ohos.faultLogger @ohos.hiviewdfx.hiAppEvent
console console.log @ohos.hilog (Recommended)
window Global window.getTopWindow windowStage.getMainWindow
camera.Camera Old camera API camera.CameraManager + camera.Session
getSupportedOutputCapability Missing sceneMode parameter Add camera.SceneMode.NORMAL_VIDEO parameter
CameraInput.release() Non-existent method Use CameraInput.close() instead
imagePacker.packing() Deprecated method Use imagePacker.packToFile() instead
XComponent import from @kit.ArkUI Wrong import path Use global XComponent without import
globalThis Global context access Use UIContext, AppStorage, or LocalStorage
AppStorage.watch() Manual watch method Use @StorageLink or @StorageProp decorators
Configuration.densityDpi Screen density property Use display.getDefaultDisplaySync() or WindowProperties
TouchEvent Old API (touchPoint, pressure, tiltX/tiltY) Use event.touches, event.source
SideBarContainer Old API with boolean parameter Use conditional layout instead
SwiperItem Deprecated component Use direct child components

Usage

Detailed Migration Guides

Code Examples

Refer to the documentation links above for detailed steps.

Weekly Installs
1
GitHub Stars
2
First Seen
10 days ago
Installed on
amp1
cline1
opencode1
cursor1
kimi-cli1
codex1