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 = void 0; 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 this.currentTime = this.currentTime + '\n' + date.toString(); 43 }); 44 } catch(e) { 45 console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`); 46 } 47 }) 48 } 49 50 build() { 51 Row() { 52 Column() { 53 Text(this.message) 54 .fontSize(40) 55 .fontWeight(FontWeight.Bold) 56 Text(this.currentTime) 57 .fontSize(40) 58 .fontWeight(FontWeight.Bold) 59 } 60 .backgroundColor(Color.Green) 61 .width('100%') 62 } 63 .height('100%') 64 } 65}