StartAd.ets
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { window, promptAction, router } from '@kit.ArkUI';
import {
CSJAdSdk,
SDKConfigBuilder,
SDKConfig,
MediationConfigBuilder
} from '@csj/openadsdk';
// 创建SDKConfig对象
let adConfigBuilder = new SDKConfigBuilder()
let config: SDKConfig = adConfigBuilder
.appId("5669833")
.appName("消防维保助手")
.allowShowNotify(true)
.debug(true)
.setMediationConfig(new MediationConfigBuilder().useMediation(true).build())
.setThemeStatus(0)
.build()
@Entry
@Component
struct StartAd {
async aboutToAppear() {
// 初始化SDK
CSJAdSdk.init(getContext(this), config) //context类型必须为UIAbility,否则可能存在展示异常场景
// 启动SDK
const result = await CSJAdSdk.start()
if (result) {
if (result.code == 0 || result.code == 4200) {
router.replaceUrl({ url: 'pages/AdMainPage' })
// this.loadOpenAd()
} else {
promptAction.showToast({ message: result.msg });
}
}
}
closeWin() {
const win = window.findWindow('startAd') // 找到子窗口
win.destroyWindow() // 销毁窗口
}
build() {
Column() {
Stack(){
Progress({ value: 0, total: 10, type: ProgressType.Ring })
.width(120).color('#409EFF').backgroundColor('#fff')
.style({ strokeWidth: 10, status: ProgressStatus.LOADING })
Image($r('app.media.logo')).width(60).height(60)
}
}.width('100%').height('100%').justifyContent(FlexAlign.Center)
}
}