1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 16import systemDateTime from '@ohos.systemDateTime'; 17import Logger from '../log/HiAdLog'; 18 19const TAG = 'AutoRefreshAdPage'; 20const storage = LocalStorage.GetShared(); 21 22@Entry(storage) 23@Component 24struct AutoRefreshPage { 25 @State message: string = 'AutoRefreshPage'; 26 @State currentTime: string = ''; 27 @LocalStorageLink('session') session: UIExtensionContentSession = new UIExtensionContentSession(); 28 29 aboutToAppear() { 30 Logger.i(TAG, '%{public}s', 'aboutToAppear'); 31 this.session?.sendData({ status: 'onAdOpen', ad: {}, data: 'AdsTest' }); 32 33 this.session.setReceiveDataCallback((data) => { 34 Logger.i(TAG, `setReceiveDataCallback:${(JSON.stringify(data))}`); 35 try { 36 systemDateTime.getDate((error, date) => { 37 if (error) { 38 console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`); 39 return; 40 } 41 console.info(`Succeeded in getting date : ${date}`); 42 ; 43 this.currentTime = this.currentTime + '\n' + date.toString(); 44 }); 45 } catch (e) { 46 console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`); 47 } 48 }) 49 } 50 51 build() { 52 Row() { 53 Column() { 54 Text(this.message) 55 .fontSize(40) 56 .fontWeight(FontWeight.Bold) 57 Text(this.currentTime) 58 .fontSize(40) 59 .fontWeight(FontWeight.Bold) 60 } 61 .backgroundColor(Color.Green) 62 .width('100%') 63 } 64 .height('100%') 65 } 66}