diff --git a/PreHttpRequestUseFiles/README.md b/PreHttpRequestUseFiles/README.md index 53004a129808189e51b667bc751296976596cf0c..1189227ba7931ea8fc46a209712777b9d431a097 100644 --- a/PreHttpRequestUseFiles/README.md +++ b/PreHttpRequestUseFiles/README.md @@ -22,6 +22,8 @@ ├──entry/src/main/ets │ ├──entryability │ │ └──EntryAbility.ets // 程序入口类 +│ ├──entrybackupability +│ │ └──EntryBackupAbility.ets // 应用数据备份恢复类 │ ├──pages │ │ ├──MainPage.ets // 视图层-父页面 │ │ └──PageOne.ets // 视图层-子页面 diff --git a/PreHttpRequestUseFiles/entry/src/main/ets/pages/MainPage.ets b/PreHttpRequestUseFiles/entry/src/main/ets/pages/MainPage.ets index a27e8f7a75315d3b36c9a1fa22b1bee6d2f2e618..842afe2d8331a27ba5a0cfbe815cc16e7e1c3c0f 100644 --- a/PreHttpRequestUseFiles/entry/src/main/ets/pages/MainPage.ets +++ b/PreHttpRequestUseFiles/entry/src/main/ets/pages/MainPage.ets @@ -21,12 +21,12 @@ import Logger from '../utils/Logger'; // Obtain the path of the application file const uiContext: UIContext | undefined = AppStorage.get('uiContext'); -let context = uiContext?.getHostContext() as common.UIAbilityContext; -let filesDir = context.filesDir; -let fileUrl = filesDir + '/xxx.png'; // The image's network address suffix needs to be replaced by the real url. +let context: common.UIAbilityContext = uiContext?.getHostContext() as common.UIAbilityContext; +let filesDir: string = context.filesDir; +let fileUrl: string = filesDir + '/xxx.png'; // The image's network address suffix needs to be replaced by the real url. let para: Record = { 'imageData': undefined }; let localStorage: LocalStorage = new LocalStorage(para); -const TAG = '[GetPixMapFunc]'; +const TAG: string = '[GetPixMapFunc]'; @Entry(localStorage) @Component @@ -36,7 +36,7 @@ struct MainPage { getPixMap() { // Read files from the application sandbox try { - let file = fs.openSync(fileUrl, fs.OpenMode.READ_WRITE); // Open the file in a synchronous manner + let file: fs.File = fs.openSync(fileUrl, fs.OpenMode.READ_WRITE); // Open the file in a synchronous manner const imageSource: image.ImageSource = image.createImageSource(file.fd); const options: image.InitializationOptions = { 'alphaType': 0, // transparency diff --git a/PreHttpRequestUseFiles/entry/src/main/ets/utils/NetRequest.ets b/PreHttpRequestUseFiles/entry/src/main/ets/utils/NetRequest.ets index 564eb341a91fd0bddbe312ecdb1f3940ecc47ebb..61f265455cfe4dab751467c59f939dbe419b9d9a 100644 --- a/PreHttpRequestUseFiles/entry/src/main/ets/utils/NetRequest.ets +++ b/PreHttpRequestUseFiles/entry/src/main/ets/utils/NetRequest.ets @@ -20,9 +20,9 @@ import { common } from '@kit.AbilityKit'; // Obtain the path of the application file const uiContext: UIContext | undefined = AppStorage.get('uiContext'); -let context = uiContext?.getHostContext() as common.UIAbilityContext; -let filesDir = context.filesDir; -let fileUrl = filesDir + '/xxx.png'; // The image's network address suffix needs to be replaced by the real url. +let context: common.UIAbilityContext = uiContext?.getHostContext() as common.UIAbilityContext; +let filesDir: string = context.filesDir; +let fileUrl: string = filesDir + '/xxx.png'; // The image's network address suffix needs to be replaced by the real url. export async function httpRequest() { fs.access(fileUrl, fs.AccessModeType.READ).then((res) => { // Check whether files exist @@ -50,7 +50,7 @@ export async function httpRequest() { // Write to the sandbox async function readWriteFileWithStream(imageData: ArrayBuffer): Promise { - let outputStream = fs.createStreamSync(fileUrl, 'w+'); + let outputStream: fs.Stream = fs.createStreamSync(fileUrl, 'w+'); await outputStream.write(imageData); outputStream.closeSync(); } diff --git a/PreHttpRequestUseFiles/entry/src/main/resources/base/element/string.json b/PreHttpRequestUseFiles/entry/src/main/resources/base/element/string.json index 32ea56af0ac0e3390dadd8496a9aaee7390a4aaa..9a4e74633ce81531696f4759fc297b2a1a990083 100644 --- a/PreHttpRequestUseFiles/entry/src/main/resources/base/element/string.json +++ b/PreHttpRequestUseFiles/entry/src/main/resources/base/element/string.json @@ -10,7 +10,7 @@ }, { "name": "EntryAbility_label", - "value": "label" + "value": "PreHttpRequestUseFiles" }, { "name": "internet_reason", diff --git a/PreHttpRequestUseFiles/entry/src/main/resources/en_US/element/string.json b/PreHttpRequestUseFiles/entry/src/main/resources/en_US/element/string.json index 32ea56af0ac0e3390dadd8496a9aaee7390a4aaa..9a4e74633ce81531696f4759fc297b2a1a990083 100644 --- a/PreHttpRequestUseFiles/entry/src/main/resources/en_US/element/string.json +++ b/PreHttpRequestUseFiles/entry/src/main/resources/en_US/element/string.json @@ -10,7 +10,7 @@ }, { "name": "EntryAbility_label", - "value": "label" + "value": "PreHttpRequestUseFiles" }, { "name": "internet_reason", diff --git a/PreHttpRequestUseFiles/entry/src/main/resources/zh_CN/element/string.json b/PreHttpRequestUseFiles/entry/src/main/resources/zh_CN/element/string.json index 2cfac88316a0993b7b743aadbf5a58811ef9bc69..aac03c8c216535da2c05b7aa1cc5a2af69a839c2 100644 --- a/PreHttpRequestUseFiles/entry/src/main/resources/zh_CN/element/string.json +++ b/PreHttpRequestUseFiles/entry/src/main/resources/zh_CN/element/string.json @@ -10,7 +10,7 @@ }, { "name": "EntryAbility_label", - "value": "label" + "value": "PreHttpRequestUseFiles" }, { "name": "internet_reason",