• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.advertising.AdComponent (Non-Full-Screen Ad Component)
2
3
4The AdComponent module provides the capability of displaying non-full-screen ads.
5
6
7> **NOTE**
8>
9> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
10
11
12## Modules to Import
13
14```ts
15import { AdComponent } from '@ohos.advertising.AdComponent';
16```
17
18
19## AdComponent
20
21AdComponent(ads: Array<advertising.Advertisement>, displayOptions: advertising.AdDisplayOptions, interactionListener: advertising.AdInteractionListener): void
22
23Shows a non-full-screen ad.
24
25**System capability**: SystemCapability.Advertising.Ads
26
27**Since**: 11
28
29
30**Parameters**
31
32
33| Name| Type| Mandatory| Description|
34| -------- | -------- | -------- | -------- |
35| ads | Array<advertising.[Advertisement](js-apis-advertising.md#advertisement)> | Yes| Array of ad objects.|
36| displayOptions | advertising.[AdDisplayOptions](js-apis-advertising.md#addisplayoptions) | Yes| Ad display parameters.|
37| interactionListener | advertising.[AdInteractionListener](js-apis-advertising.md#adinteractionlistener) | Yes| Ad status change callback.|
38
39**Example**
40
41```ts
42import advertising from '@ohos.advertising';
43import { AdComponent } from '@ohos.advertising.AdComponent';
44import hilog from '@ohos.hilog';
45
46@Component
47export struct ShowNonFullScreenAd {
48  // Requested ad content.
49  private ads: Array<advertising.Advertisement> = [];
50  // Ad display parameters.
51  private adDisplayOptions: advertising.AdDisplayOptions = {
52    // Whether to mute the ad. By default, the ad is not muted.
53    mute: false,
54  }
55
56  build() {
57    Column() {
58      // The AdComponent is used to show the non-full-screen ad.
59      AdComponent({ ads: this.ads, displayOptions: this.adDisplayOptions,
60        interactionListener: {
61          // Ad status change callback.
62          onStatusChanged: (status: string, ad: advertising.Advertisement, data: string) => {
63            switch(status) {
64              case 'onAdOpen':
65                hilog.info(0x0000, 'testTag', '%{public}s', 'onAdOpen');
66                break;
67              case 'onAdClick':
68                hilog.info(0x0000, 'testTag', '%{public}s', 'onAdClick');
69                break;
70              case 'onAdClose':
71                hilog.info(0x0000, 'testTag', '%{public}s', 'onAdClose');
72                break;
73            }
74          }}})
75        .width('100%')
76        .height('100%')
77    }.width('100%').height('100%')
78  }
79}
80```
81