diff --git a/AbilityKit/entry/src/main/ets/pages/GetCacheDirectoryView.ets b/AbilityKit/entry/src/main/ets/pages/GetCacheDirectoryView.ets index 47e4a1dd9331afe9556d81e2c18ca747aaefc33d..b5d7c8a2b073d8b3030e3ddecb6cab4f2b5d0bfb 100644 --- a/AbilityKit/entry/src/main/ets/pages/GetCacheDirectoryView.ets +++ b/AbilityKit/entry/src/main/ets/pages/GetCacheDirectoryView.ets @@ -23,7 +23,7 @@ import { common } from '@kit.AbilityKit'; @Entry @Component export struct GetCacheDirectoryView { - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; @State cachePath: string = ''; build() { diff --git a/AbilityKit/entry/src/main/ets/pages/GetRaw.ets b/AbilityKit/entry/src/main/ets/pages/GetRaw.ets index 5f811eb1a517b64f4f44d678e284a0907b0df5e4..26dd3a5ed4d91cc39fad4f2faa305d596c9037d6 100644 --- a/AbilityKit/entry/src/main/ets/pages/GetRaw.ets +++ b/AbilityKit/entry/src/main/ets/pages/GetRaw.ets @@ -23,8 +23,8 @@ import { common } from '@kit.AbilityKit'; // Passing in '' indicates obtaining a list of files in the root directory of rawfile try { - let context = getContext(this) as common.UIAbilityContext; - context.resourceManager.getRawFileList('', (error: BusinessError, value: Array) => { + let context = AppStorage.get("context") as UIContext; + context.getHostContext()!.resourceManager.getRawFileList('', (error: BusinessError, value: Array) => { if (error != null) { console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); } else { diff --git a/AbilityKit/entry/src/main/ets/pages/PullUpCamera.ets b/AbilityKit/entry/src/main/ets/pages/PullUpCamera.ets index 475d31fe25fcfb679bda058140b624894a78924e..a0eafcc4b0f3dd3e0a9a22efe2f44810a5a2ac15 100644 --- a/AbilityKit/entry/src/main/ets/pages/PullUpCamera.ets +++ b/AbilityKit/entry/src/main/ets/pages/PullUpCamera.ets @@ -22,14 +22,14 @@ import { common } from '@kit.AbilityKit'; import { camera, cameraPicker } from '@kit.CameraKit'; import { BusinessError } from '@kit.BasicServicesKit'; -let context = getContext(this) as common.Context; +let context = AppStorage.get("context") as UIContext; async function startCameraPicker() { try { let pickerProfile: cameraPicker.PickerProfile = { cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK }; - let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(context, + let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(context.getHostContext(), [cameraPicker.PickerMediaType.PHOTO, cameraPicker.PickerMediaType.VIDEO], pickerProfile); console.log("the pick pickerResult is:" + JSON.stringify(pickerResult)); } catch (error) { diff --git a/AbilityKit/entry/src/main/ets/pages/StartAppGallery.ets b/AbilityKit/entry/src/main/ets/pages/StartAppGallery.ets index 9545dac9f02cdebd75ee25a308ac23caf876309f..dec097aeb9b450876c42dc8e236a29063e7f9182 100644 --- a/AbilityKit/entry/src/main/ets/pages/StartAppGallery.ets +++ b/AbilityKit/entry/src/main/ets/pages/StartAppGallery.ets @@ -46,7 +46,7 @@ struct StartAppGalleryDetailAbilityView { .fontSize(24) .fontWeight(FontWeight.Bold) .onClick(() => { - const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + const context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; const bundleName = 'com.example.xxx'; startAppGalleryDetailAbility(context, bundleName); }) diff --git a/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets b/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets index 3181b258bdc8f25e584f4deeb8f507b8c229eca3..fcab9df4c3ff82b3473e7d36cc73580bd04c17d6 100644 --- a/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets +++ b/ArkUI/entry/src/main/ets/pages/TheHeaderTruncated.ets @@ -33,7 +33,7 @@ export struct SubWindowPage { @State screenHeight: number | string = '100%'; aboutToAppear() { - window.getLastWindow(getContext(this)).then(currentWindow => { + window.getLastWindow(this.getUIContext().getHostContext()).then(currentWindow => { // Monitor keyboard pop-up and collapse currentWindow.on('avoidAreaChange', async data => { let property = currentWindow.getWindowProperties(); diff --git a/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Four.ets b/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Four.ets index ae2973ad4c47db84832d4d6b7f8a554efafba991..4bda34c9ca4430cfbd65db0827389e1863700827 100644 --- a/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Four.ets +++ b/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Four.ets @@ -32,7 +32,7 @@ struct WebComponent { Column() { Web({ src: $rawfile('hello.html'), controller: this.controller }) .onLoadIntercept((event) => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext let want: Want = { deviceId: '', // An empty DeviceId indicates that this device bundleName: '***', // BundleName of the third-party application you want to jump to diff --git a/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Three.ets b/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Three.ets index b3b90ff7bc6a825b6e27f6f5a793757a98a78432..d341028cd7d550e8ddcbe6e108df5e995e3e4a89 100644 --- a/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Three.ets +++ b/ArkWebKit/entry/src/main/ets/pages/UseLabelAOpenPages_Three.ets @@ -40,7 +40,7 @@ function startSettingsInfo(context: common.UIAbilityContext,uri : string): void @Entry @Component struct WebComponent { - context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; controller: webview.WebviewController = new webview.WebviewController(); build() { Column() { diff --git a/ArkWebKit/entry/src/main/ets/pages/UseWebDownloadPdf.ets b/ArkWebKit/entry/src/main/ets/pages/UseWebDownloadPdf.ets index 507730200c8726d40235c56e55678f5054e51867..0f322b596ea6fb308fb7cd80f784430da65765db 100644 --- a/ArkWebKit/entry/src/main/ets/pages/UseWebDownloadPdf.ets +++ b/ArkWebKit/entry/src/main/ets/pages/UseWebDownloadPdf.ets @@ -72,7 +72,7 @@ struct Index { .fileAccess(true) .domStorageAccess(true) .onPageBegin((event) => { - request.agent.create(getContext(), config).then((task: request.agent.Task) => { + request.agent.create(this.getUIContext().getHostContext(), config).then((task: request.agent.Task) => { task.on('completed', createOnCallback); console.info(`Succeeded in creating a download task. result: ${task.config}`); task.start(); diff --git a/CoreFileKit/entry/src/main/ets/pages/GetRawfile.ets b/CoreFileKit/entry/src/main/ets/pages/GetRawfile.ets index ecbd2a9e51c58256221874edf51b701b025f1342..d9219e147fd2f85511a4d5dd7aee0e822b46a075 100644 --- a/CoreFileKit/entry/src/main/ets/pages/GetRawfile.ets +++ b/CoreFileKit/entry/src/main/ets/pages/GetRawfile.ets @@ -25,7 +25,7 @@ export struct GetRawfile { @State message: string = 'Hello World'; aboutToAppear(): void { - getContext(this).resourceManager.getRawFileContent('test.txt', (_err, value) => { + this.getUIContext().getHostContext()?.resourceManager.getRawFileContent('test.txt', (_err, value) => { let myBuffer: ArrayBufferLike = value.buffer; let context = this.getUIContext().getHostContext(); //Sandbox Path let filePath = context!.filesDir + '/test.txt'; diff --git a/ImageKit/CPixelMapToMat/src/main/ets/pages/Index.ets b/ImageKit/CPixelMapToMat/src/main/ets/pages/Index.ets index 348ab7a225789bb07bcbce4a6aa7ae1eb7260598..a556cf1e96a539fc9aceabc5ada82fbe794bf42d 100644 --- a/ImageKit/CPixelMapToMat/src/main/ets/pages/Index.ets +++ b/ImageKit/CPixelMapToMat/src/main/ets/pages/Index.ets @@ -29,7 +29,8 @@ struct Index { async arrayBufferToMat() { if (this.pixelMap == undefined || this.pixelMap){ - let resourceManager = getContext(this).resourceManager + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let resourceManager = context.resourceManager let imageArray = await resourceManager.getMediaContent($r('app.media.sample10')); let pixelBuffer = new Uint8Array(imageArray).buffer as Object as ArrayBuffer console.info("pixelBuffer length: " + pixelBuffer.byteLength); diff --git a/ImageKit/entry/src/main/ets/pages/CreatePixelMapError2.ets b/ImageKit/entry/src/main/ets/pages/CreatePixelMapError2.ets index 77753681217e6835d81994ad3b641a0286d032af..f3b9f1af3ad4cd6f47320dc18f582af3b1549ee9 100644 --- a/ImageKit/entry/src/main/ets/pages/CreatePixelMapError2.ets +++ b/ImageKit/entry/src/main/ets/pages/CreatePixelMapError2.ets @@ -26,8 +26,8 @@ let decodingOptions: image.DecodingOptions = { desiredPixelFormat: 3, desiredSize: { width: 4,height: 6 } } -const context: Context = getContext(this); -const filePath: string = context.cacheDir + '/test.jpg'; +const context= AppStorage.get("context") as UIContext; +const filePath: string = context.getHostContext()?.cacheDir + '/test.jpg'; const imageSource: image.ImageSource = image.createImageSource(filePath); // Create PixelMap and perform simple rotation and scaling imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => { diff --git a/ImageKit/entry/src/main/ets/pages/PixelFormat.ets b/ImageKit/entry/src/main/ets/pages/PixelFormat.ets index c7a95e2453514638c01d6a62a336fc51ac824793..6fae8a64573e4c0c01f27108208823e4edc74dca 100644 --- a/ImageKit/entry/src/main/ets/pages/PixelFormat.ets +++ b/ImageKit/entry/src/main/ets/pages/PixelFormat.ets @@ -36,7 +36,7 @@ struct Index { .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(async () => { - let resourceManager = getContext(this).resourceManager + let resourceManager = this.getUIContext().getHostContext()!.resourceManager let imageArray = await resourceManager.getMediaContent($r("app.media.sample14_NV21_fromJPG_510X510")); let pixelBuffer = new Uint8Array(imageArray).buffer as Object as ArrayBuffer; // The value 8 of the sourcePixelFormat parameter corresponds to NV21 format, and 9 corresponds to NV12 format; The sourceSize parameter needs to set the width and height (the width and height data of the original yuv image), and the width value cannot be odd. diff --git a/LocalizationKit/entry/src/main/ets/pages/GetRawfile.ets b/LocalizationKit/entry/src/main/ets/pages/GetRawfile.ets index 22682f26f5b4f30a1f2e616c4673924c045a8938..038335c0416d4b8a896f9d1ec9aa10aeba5d1db7 100644 --- a/LocalizationKit/entry/src/main/ets/pages/GetRawfile.ets +++ b/LocalizationKit/entry/src/main/ets/pages/GetRawfile.ets @@ -25,7 +25,7 @@ import { buffer } from '@kit.ArkTS'; @Entry @Component struct Index { - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext;; build() { Column() { diff --git a/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets b/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets index 43f85ca1a8b71342ad3796b700f2a2a8e38c58e2..f81fab811fa5ae5536a25e984330682567882b25 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets @@ -23,8 +23,8 @@ import { fileIo } from '@kit.CoreFileKit'; import { common } from '@kit.AbilityKit'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; -let context = getContext(this) as common.UIAbilityContext; -let filesDir = context.filesDir; +let context = AppStorage.get("context") as UIContext; +let filesDir = context.getHostContext()?.filesDir; function SavePictureToContext(){ const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // Filter and select media file type as IMAGE diff --git a/Ndk/Ndk2/CSideOpenFile/src/main/ets/pages/Index.ets b/Ndk/Ndk2/CSideOpenFile/src/main/ets/pages/Index.ets index fdf95a1a50d51e521475e96645c3468048d3b0e0..26f3e4109bb145d10596a3516529c62a77ad639f 100644 --- a/Ndk/Ndk2/CSideOpenFile/src/main/ets/pages/Index.ets +++ b/Ndk/Ndk2/CSideOpenFile/src/main/ets/pages/Index.ets @@ -21,6 +21,7 @@ import { fileIo} from '@kit.CoreFileKit'; import { BusinessError } from '@kit.BasicServicesKit'; import testNapi from 'libentry.so'; +import { common } from '@kit.AbilityKit'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; @Entry @@ -44,7 +45,8 @@ struct Index { let file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY); console.info('file fd: ' + file.fd); let fd = file.fd - let filesDir = getContext(this).filesDir; + let context = this.getUIContext().getHostContext() as common.UIAbilityContext + let filesDir = context.filesDir; fileIo.copyFileSync(fd, filesDir + '/test2.jpg') let file2 = fileIo.openSync(filesDir + '/test2.jpg', fileIo.OpenMode.READ_ONLY); let file3 = fileIo.openSync(filesDir + '/test3.jpg', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);