diff --git a/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets b/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets index 99a1989ce7d40c5c7823eb69de9313589a8153e8..79a8d8ef1080b535cdb9c2eb9155a6f759774218 100644 --- a/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets +++ b/NetworkReconnection/entry/src/main/ets/pages/HTTPReconnection.ets @@ -103,7 +103,7 @@ export struct HTTPReconnection { }); this.httpRequest.on('dataEnd', () => { - promptAction.showToast({ message: $r('app.string.download_success') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_success') }); this.downloadSize = 0; this.contentLength = 0; fs.closeSync(file); @@ -135,7 +135,8 @@ export struct HTTPReconnection { }); } catch (err) { this.isDownload = false; - promptAction.showToast({ message: "Download Error" }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_error') }); + this.getUIContext().getPromptAction().showToast({ message: "Download Error" }); return; } } diff --git a/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets b/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets index f003321e73940f215c0157c80f51f90bf80e6603..cfa194f5e455d58def6eb5a2543be5ef6bae666e 100644 --- a/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets +++ b/NetworkReconnection/entry/src/main/ets/pages/RCPReconnection.ets @@ -129,7 +129,7 @@ export struct RCPReconnection { fs.writeSync(file.fd, response.body); fs.closeSync(file); this.isDownload = false; - promptAction.showToast({ message: $r('app.string.download_success') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_success') }); } catch (err) { Logger.info(JSON.stringify(err)); } finally { @@ -156,7 +156,8 @@ export struct RCPReconnection { } }) } catch (err) { - promptAction.showToast({ message: "Download Error" }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_error') }); + this.getUIContext().getPromptAction().showToast({ message: "Download Error" }); this.isDownload = false; return; } diff --git a/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets b/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets index c5bf10dcd83f900f17b50600ff80a8a7976bc84b..566dd7cdb711caa8f90fedaba45a41bc603b0cba 100644 --- a/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets +++ b/NetworkReconnection/entry/src/main/ets/pages/SocketReconnection.ets @@ -118,7 +118,8 @@ export struct SocketReconnection { tcpSocketConnect() { if (!this.netAvailable) { - promptAction.showToast({ message: "Connect error" }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.connect_error') }); + this.getUIContext().getPromptAction().showToast({ message: "Connect error" }); return; } @@ -141,7 +142,8 @@ export struct SocketReconnection { this.tcp.bind(clientIpAddress, (err: BusinessError) => { if (err) { Logger.error('bind fail' + JSON.stringify(err)); - promptAction.showToast({ message: "Connect error" }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.connect_error') }); + this.getUIContext().getPromptAction().showToast({ message: "Connect error" }); return; } @@ -155,7 +157,8 @@ export struct SocketReconnection { this.tcp?.connect(tcpConnect, (err: BusinessError) => { if (err) { Logger.error('connect fail'); - promptAction.showToast({ message: "Connect error" }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.connect_error') }); + this.getUIContext().getPromptAction().showToast({ message: "Connect error" }); return; } }); @@ -169,7 +172,7 @@ export struct SocketReconnection { socketDownloadFile() { if (!this.netAvailable) { - promptAction.showToast({ message: $r('app.string.net_lost') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.net_lost') }); return; } this.isDownload = true; @@ -233,7 +236,7 @@ export struct SocketReconnection { fs.writeSync(file.fd, this.receivedDataBuf.subarray(8 + i * (1024 * 1024 + 8), this.receivedDataLen).buffer, { offset: offset }); fs.close(file); - promptAction.showToast({ message: $r('app.string.download_success') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.download_success') }); this.stateInit(); } } diff --git a/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets b/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets index 9726939f43ee987c2c106b433df7ad1904747b56..751cf2c85db3ae63f900544015d33dbd2ed0e6ff 100644 --- a/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets +++ b/ServerSocket/entry/src/main/ets/pages/ServerSocketPage.ets @@ -115,7 +115,7 @@ struct ServerSocketPage { }; wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => { - backgroundTaskManager.startBackgroundRunning(getContext(this), + backgroundTaskManager.startBackgroundRunning(this.getUIContext().getHostContext(), backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { this.connectInit(); Logger.info(`Succeeded in operationing startBackgroundRunning.`); @@ -126,7 +126,7 @@ struct ServerSocketPage { } stopContinuousTask() { - backgroundTaskManager.stopBackgroundRunning(getContext(this)).then(() => { + backgroundTaskManager.stopBackgroundRunning(this.getUIContext().getHostContext()).then(() => { Logger.info(`Succeeded in operationing stopBackgroundRunning.`); }).catch((err: BusinessError) => { Logger.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`); @@ -142,11 +142,11 @@ struct ServerSocketPage { return; } this.isListen = true; - promptAction.showToast({ message: $r('app.string.tcp_server_listen_tips') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.tcp_server_listen_tips') }); this.tcpServer.on('connect', (client: socket.TCPSocketConnection) => { Logger.info('on connect success'); this.isSend = true; - promptAction.showToast({ message: $r('app.string.tcp_server_connect_tips') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.tcp_server_connect_tips') }); this.socketClient = client; this.socketClient.on('close', () => { Logger.info('on close success'); @@ -164,7 +164,8 @@ struct ServerSocketPage { async sendFile() { try { - const mediaBuffer: Uint8Array = await getContext(this).resourceManager.getMediaContent($r('app.media.Video')); + const mediaBuffer: Uint8Array = + await this.getUIContext().getHostContext()!.resourceManager.getMediaContent($r('app.media.Video')); let tcpSendOptions: socket.TCPSendOptions = {} as socket.TCPSendOptions; // slice size: 1024 * 1024 const sendNum = Math.floor(mediaBuffer.byteLength / (1024 * 1024)); @@ -191,7 +192,7 @@ struct ServerSocketPage { Logger.error('send fail' + JSON.stringify(err)); return; } - promptAction.showToast({ message: $r('app.string.message_send_tips') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.message_send_tips') }); }); } } catch (err) {