1e41f4b71Sopenharmony_ci# @ohos.advertising.AdsServiceExtensionAbility (ExtensionAbility for Ads) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe AdsServiceExtensionAbility module provides ExtensionAbilities for the ads service. Device vendors can implement the service logic of requesting one or multiple ads.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci> **NOTE**
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> 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.
10e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Modules to Import
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```ts
16e41f4b71Sopenharmony_ciimport { AdsServiceExtensionAbility } from '@kit.AdsKit';
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci## AdsServiceExtensionAbility.onLoadAd
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_cionLoadAd(adParam: advertising.AdRequestParams, adOptions: advertising.AdOptions, respCallback: RespCallback);
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciCalled when the media application starts to load an ad. The device vendor needs to implement the ad request service logic in this API and send the result to the media application through a call back.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**System API**: This is a system API.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Advertising.Ads
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci**Since**: 11
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**Parameters**
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 
35e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
36e41f4b71Sopenharmony_ci| adParam | advertising.[AdRequestParams](js-apis-advertising.md#adrequestparams) | Yes| Ad request parameters.| 
37e41f4b71Sopenharmony_ci| adOptions | advertising.[AdOptions](js-apis-advertising.md#adoptions) | Yes| Ad configuration.| 
38e41f4b71Sopenharmony_ci| respCallback | [RespCallback](js-apis-adsserviceextensionability#adsserviceextensionabilityrespcallback) | Yes| Ad request callback.| 
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**Example**
41e41f4b71Sopenharmony_ci```ts
42e41f4b71Sopenharmony_ciimport { AdsServiceExtensionAbility, advertising, RespCallback } from '@kit.AdsKit';
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ciexport default class AdsExtensionAbility extends AdsServiceExtensionAbility {
45e41f4b71Sopenharmony_ci  onLoadAd(adParam: advertising.AdRequestParams, adOptions: advertising.AdOptions, respCallback: RespCallback) {
46e41f4b71Sopenharmony_ci    const adType: number | undefined = adParam.adType;
47e41f4b71Sopenharmony_ci    const ads: Array<advertising.Advertisement> = [];
48e41f4b71Sopenharmony_ci    const rewardVerifyConfig: Map<string, string> = new Map();
49e41f4b71Sopenharmony_ci    ads.push({
50e41f4b71Sopenharmony_ci      adType: adType as number,
51e41f4b71Sopenharmony_ci      uniqueId: '111111',
52e41f4b71Sopenharmony_ci      rewardVerifyConfig: rewardVerifyConfig,
53e41f4b71Sopenharmony_ci      rewarded: false,
54e41f4b71Sopenharmony_ci      shown: false,
55e41f4b71Sopenharmony_ci      clicked: false
56e41f4b71Sopenharmony_ci    });
57e41f4b71Sopenharmony_ci    ads.push({
58e41f4b71Sopenharmony_ci      adType: adType as number,
59e41f4b71Sopenharmony_ci      uniqueId: '222222',
60e41f4b71Sopenharmony_ci      rewardVerifyConfig: rewardVerifyConfig,
61e41f4b71Sopenharmony_ci      rewarded: false,
62e41f4b71Sopenharmony_ci      shown: false,
63e41f4b71Sopenharmony_ci      clicked: false
64e41f4b71Sopenharmony_ci    });
65e41f4b71Sopenharmony_ci    const slot: string = 'test';
66e41f4b71Sopenharmony_ci    const resMap: Map<string, Array<advertising.Advertisement>> = new Map();
67e41f4b71Sopenharmony_ci    resMap.set(slot, ads);
68e41f4b71Sopenharmony_ci    respCallback(resMap);
69e41f4b71Sopenharmony_ci  }
70e41f4b71Sopenharmony_ci}
71e41f4b71Sopenharmony_ci```
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci## AdsServiceExtensionAbility.onLoadAdWithMultiSlots
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_cionLoadAdWithMultiSlots(adParams: advertising.AdRequestParams[], adOptions: advertising.AdOptions, respCallback: RespCallback);
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ciCalled when the media application starts to load multiple ads. The device vendor needs to implement the ad request service logic in this API and send the result to the media application through a call back.
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**System API**: This is a system API.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Advertising.Ads
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Since**: 11
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**Parameters**
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 
89e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
90e41f4b71Sopenharmony_ci| adParams | advertising.[AdRequestParams](js-apis-advertising.md#adrequestparams)[] | Yes| Ad request parameters.| 
91e41f4b71Sopenharmony_ci| adOptions | advertising.[AdOptions](js-apis-advertising.md#adoptions) | Yes| Ad configuration.| 
92e41f4b71Sopenharmony_ci| respCallback | [RespCallback](js-apis-adsserviceextensionability#adsserviceextensionabilityrespcallback) | Yes| Ad request callback.| 
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**Example**
95e41f4b71Sopenharmony_ci```ts
96e41f4b71Sopenharmony_ciimport { AdsServiceExtensionAbility, advertising, RespCallback } from '@kit.AdsKit';
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ciexport default class AdsExtensionAbility extends AdsServiceExtensionAbility {
99e41f4b71Sopenharmony_ci  onLoadAdWithMultiSlots(adParams: advertising.AdRequestParams[], adOptions: advertising.AdOptions,
100e41f4b71Sopenharmony_ci    respCallback: RespCallback) {
101e41f4b71Sopenharmony_ci    const adType1: number = adParams[0].adType as number;
102e41f4b71Sopenharmony_ci    const ads1: Array<advertising.Advertisement> = [];
103e41f4b71Sopenharmony_ci    const rewardVerifyConfig: Map<string, string> = new Map();
104e41f4b71Sopenharmony_ci    ads1.push({
105e41f4b71Sopenharmony_ci      adType: adType1,
106e41f4b71Sopenharmony_ci      uniqueId: '111111',
107e41f4b71Sopenharmony_ci      rewardVerifyConfig: rewardVerifyConfig,
108e41f4b71Sopenharmony_ci      rewarded: false,
109e41f4b71Sopenharmony_ci      shown: false,
110e41f4b71Sopenharmony_ci      clicked: false
111e41f4b71Sopenharmony_ci    });
112e41f4b71Sopenharmony_ci    ads1.push({
113e41f4b71Sopenharmony_ci      adType: adType1,
114e41f4b71Sopenharmony_ci      uniqueId: '222222',
115e41f4b71Sopenharmony_ci      rewardVerifyConfig: rewardVerifyConfig,
116e41f4b71Sopenharmony_ci      rewarded: false,
117e41f4b71Sopenharmony_ci      shown: false,
118e41f4b71Sopenharmony_ci      clicked: false
119e41f4b71Sopenharmony_ci    });
120e41f4b71Sopenharmony_ci    const slot1: string = 'test1';
121e41f4b71Sopenharmony_ci    const adType2: number = adParams[1].adType as number;
122e41f4b71Sopenharmony_ci    const ads2: Array<advertising.Advertisement> = [];
123e41f4b71Sopenharmony_ci    ads2.push({
124e41f4b71Sopenharmony_ci      adType: adType2,
125e41f4b71Sopenharmony_ci      uniqueId: '333333',
126e41f4b71Sopenharmony_ci      rewardVerifyConfig: rewardVerifyConfig,
127e41f4b71Sopenharmony_ci      rewarded: false,
128e41f4b71Sopenharmony_ci      shown: false,
129e41f4b71Sopenharmony_ci      clicked: false
130e41f4b71Sopenharmony_ci    });
131e41f4b71Sopenharmony_ci    ads2.push({
132e41f4b71Sopenharmony_ci      adType: adType2,
133e41f4b71Sopenharmony_ci      uniqueId: '444444',
134e41f4b71Sopenharmony_ci      rewardVerifyConfig: rewardVerifyConfig,
135e41f4b71Sopenharmony_ci      rewarded: false,
136e41f4b71Sopenharmony_ci      shown: false,
137e41f4b71Sopenharmony_ci      clicked: false
138e41f4b71Sopenharmony_ci    });
139e41f4b71Sopenharmony_ci    const slot2: string = 'test2';
140e41f4b71Sopenharmony_ci    const resMap: Map<string, Array<advertising.Advertisement>> = new Map();
141e41f4b71Sopenharmony_ci    resMap.set(slot1, ads1);
142e41f4b71Sopenharmony_ci    resMap.set(slot2, ads2);
143e41f4b71Sopenharmony_ci    respCallback(resMap);
144e41f4b71Sopenharmony_ci  }
145e41f4b71Sopenharmony_ci}
146e41f4b71Sopenharmony_ci```
147