emi-indo-cordova-plugin-admob 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +262 -38
- package/example/index.html +107 -17
- package/package.json +1 -1
- package/plugin.xml +2 -2
- package/src/android/emiAdmobPlugin.java +1 -1
- package/www/emiAdmobPlugin.js +16 -9
package/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# emi-indo-cordova-plugin-admob
|
2
2
|
Cordova Plugin Admob Android
|
3
3
|
|
4
|
-
### Mobile Ads SDK (Android:
|
4
|
+
### Mobile Ads SDK (Android: 22.0.0)
|
5
5
|
[Release Notes:](https://developers.google.com/admob/android/rel-notes)
|
6
6
|
|
7
7
|
> __Warning__
|
8
|
-
> Updating the Mobile Ads SDK version may cause some code to malfunction, as the latest version usually deprecates some older code, [scrrenshot](https://drive.google.com/file/d/1UKaEjdmGRXgdZ2DKfOne8BSq13IUY14_/view) Current plugin code SDK
|
8
|
+
> Updating the Mobile Ads SDK version may cause some code to malfunction, as the latest version usually deprecates some older code, [scrrenshot](https://drive.google.com/file/d/1UKaEjdmGRXgdZ2DKfOne8BSq13IUY14_/view) Current plugin code SDK 22.0.0
|
9
9
|
|
10
10
|
> __Warning__
|
11
|
-
> If the cordova admob plugin using Mobile Ads SDK code version 20.6.0 is upgraded to Mobile Ads SDK version
|
11
|
+
> If the cordova admob plugin using Mobile Ads SDK code version 20.6.0 is upgraded to Mobile Ads SDK version 22.0.0, some of the old plugin code will not work.
|
12
12
|
|
13
13
|
|
14
14
|
> __Note__
|
@@ -27,7 +27,9 @@ https://user-images.githubusercontent.com/78555833/228323239-e9e18e74-b814-4ca8-
|
|
27
27
|
|
28
28
|
|
29
29
|
|
30
|
-
|
30
|
+
## 💰Sponsor this project
|
31
|
+
[](https://paypal.me/emiindo)
|
32
|
+
|
31
33
|
## Features
|
32
34
|
|
33
35
|
- Banner Ads
|
@@ -55,41 +57,55 @@ cordova plugin add https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob --v
|
|
55
57
|
cordova plugin rm emi-indo-cordova-plugin-admob
|
56
58
|
```
|
57
59
|
|
58
|
-
##
|
60
|
+
## upgrade Mobile Ads SDK
|
59
61
|
[Release Notes Mobile Ads SDK:](https://developers.google.com/admob/android/rel-notes)
|
60
62
|
```sh
|
61
|
-
cordova plugin add
|
63
|
+
cordova plugin add emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713 --variable PLAY_SERVICES_VERSION="xxxx"
|
62
64
|
```
|
63
65
|
|
66
|
+
## Response Info
|
67
|
+
- Here is a sample output returned by responseInfo = true showing the debugging data returned for a loaded ad:
|
64
68
|
|
69
|
+
```sh
|
70
|
+
{
|
71
|
+
"Response ID": "COOllLGxlPoCFdAx4Aod-Q4A0g",
|
72
|
+
"Mediation Adapter Class Name": "com.google.ads.mediation.admob.AdMobAdapter",
|
73
|
+
"Adapter Responses": [
|
74
|
+
{
|
75
|
+
"Adapter": "com.google.ads.mediation.admob.AdMobAdapter",
|
76
|
+
"Latency": 328,
|
77
|
+
"Ad Source Name": "Reservation campaign",
|
78
|
+
"Ad Source ID": "7068401028668408324",
|
79
|
+
"Ad Source Instance Name": "[DO NOT EDIT] Publisher Test Interstitial",
|
80
|
+
"Ad Source Instance ID": "4665218928925097",
|
81
|
+
"Credentials": {},
|
82
|
+
"Ad Error": "null"
|
83
|
+
}
|
84
|
+
],
|
85
|
+
"Loaded Adapter Response": {
|
86
|
+
"Adapter": "com.google.ads.mediation.admob.AdMobAdapter",
|
87
|
+
"Latency": 328,
|
88
|
+
"Ad Source Name": "Reservation campaign",
|
89
|
+
"Ad Source ID": "7068401028668408324",
|
90
|
+
"Ad Source Instance Name": "[DO NOT EDIT] Publisher Test Interstitial",
|
91
|
+
"Ad Source Instance ID": "4665218928925097",
|
92
|
+
"Credentials": {},
|
93
|
+
"Ad Error": "null"
|
94
|
+
},
|
95
|
+
"Response Extras": {
|
96
|
+
"mediation_group_name": "Campaign"
|
97
|
+
}
|
98
|
+
}
|
99
|
+
```
|
65
100
|
|
66
|
-
## 💰Sponsor this project
|
67
|
-
[](https://paypal.me/emiindo)
|
68
101
|
|
69
102
|
## deviceready
|
70
103
|
|
71
104
|
[Example ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/index.html) - index.html:
|
72
105
|
|
73
106
|
|
74
|
-
|
75
|
-
|
76
107
|
```sh
|
77
108
|
|
78
|
-
|
79
|
-
var bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111"
|
80
|
-
var interstitialAdAdUnitId = "ca-app-pub-3940256099942544/1033173712"
|
81
|
-
var rewardedInterstitialAdUnitId = "ca-app-pub-3940256099942544/5354046379"
|
82
|
-
var rewardedAdAdUnitId = "ca-app-pub-3940256099942544/5224354917"
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
/// setting banner size: BANNER | LARGE_BANNER | MEDIUM_RECTANGLE | FULL_BANNER | LEADERBOARD | default: "BANNER" | (Smart Banners = DEPRECATED)
|
88
|
-
var size = "LARGE_BANNER"
|
89
|
-
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "bottom-left"
|
90
|
-
var position = "bottom-center"
|
91
|
-
|
92
|
-
|
93
109
|
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
94
110
|
// This needs to be done only once, ideally at app launch.
|
95
111
|
|
@@ -105,53 +121,178 @@ alert("on Sdk Initialization Complete");
|
|
105
121
|
```
|
106
122
|
|
107
123
|
## Banner Ads
|
124
|
+
|
125
|
+
> __Note__
|
126
|
+
### Variable name and index (final) cannot be changed.
|
127
|
+
- bannerAdUnitId | index 0
|
128
|
+
- position | index 1
|
129
|
+
- size | index 2
|
130
|
+
- adaptiveWidth | index 3
|
131
|
+
|
132
|
+
|
108
133
|
```sh
|
109
|
-
|
110
|
-
|
134
|
+
/// setting banner size: BANNER | LARGE_BANNER | MEDIUM_RECTANGLE | FULL_BANNER | LEADERBOARD | default: "BANNER" | (Smart Banners = DEPRECATED) | Inline_adaptive | Anchored_adaptive
|
135
|
+
|
136
|
+
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "bottom-left"
|
137
|
+
|
138
|
+
|
139
|
+
// Banner Adaptive
|
140
|
+
|
141
|
+
let showBannerAdaptive = () => {
|
142
|
+
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
143
|
+
bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
144
|
+
position = "bottom-center",
|
145
|
+
size = "Inline_adaptive", // | Inline_adaptive | Anchored_adaptive
|
146
|
+
adaptiveWidth = 320,
|
147
|
+
|
148
|
+
(seccess) => { console.log("success") },
|
149
|
+
(error) => { alert(error)
|
150
|
+
|
151
|
+
});
|
152
|
+
}
|
153
|
+
|
154
|
+
// call showBannerAdaptive();
|
155
|
+
|
156
|
+
// not Adaptive banner
|
157
|
+
|
158
|
+
let showBannerNotAdaptive = () => {
|
159
|
+
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
160
|
+
bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
161
|
+
position = "bottom-center",
|
162
|
+
size = "BANNER",
|
163
|
+
|
164
|
+
(seccess) => { console.log("success") },
|
165
|
+
(error) => { alert(error)
|
166
|
+
|
167
|
+
});
|
168
|
+
}
|
169
|
+
|
170
|
+
// call showBannerNotAdaptive();
|
171
|
+
|
172
|
+
// Remove Banner
|
173
|
+
|
174
|
+
let removeBannerAd = () => {
|
175
|
+
cordova.plugins.emiAdmobPlugin.removeBannerAd();
|
176
|
+
}
|
177
|
+
|
178
|
+
// call removeBannerAd();
|
179
|
+
|
111
180
|
```
|
112
181
|
[Banner ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-banner-ads-) - callback:
|
113
182
|
|
114
183
|
|
115
|
-
## Interstitial
|
184
|
+
## Interstitial Ads
|
185
|
+
|
186
|
+
> __Note__
|
187
|
+
### Variable name and index (final) cannot be changed.
|
188
|
+
- interstitialAdAdUnitId | index 0
|
189
|
+
- responseInfo | index 1
|
116
190
|
|
117
191
|
```sh
|
192
|
+
// Load Interstitial Ad
|
118
193
|
|
119
|
-
|
194
|
+
let loadInterstitialAd = () => {
|
195
|
+
cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
196
|
+
interstitialAdAdUnitId = "ca-app-pub-3940256099942544/1033173712",
|
197
|
+
responseInfo = true, // boolean (debugging)
|
198
|
+
|
199
|
+
(info) => { alert(info) },
|
200
|
+
(error) => { alert(error)
|
201
|
+
|
202
|
+
});
|
203
|
+
}
|
204
|
+
|
205
|
+
// call loadInterstitialAd();
|
206
|
+
|
207
|
+
// Show Interstitial Ad
|
208
|
+
|
209
|
+
let showInterstitialAd = () => {
|
210
|
+
cordova.plugins.emiAdmobPlugin.showInterstitialAd();
|
211
|
+
}
|
212
|
+
|
213
|
+
// call showInterstitialAd();
|
120
214
|
|
121
|
-
// Show cordova.plugins.emiAdmobPlugin.showInterstitialAd();
|
122
215
|
```
|
123
216
|
|
124
217
|
[Interstitial ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-interstitial-ads-) - callback:
|
125
218
|
|
126
219
|
|
127
220
|
|
128
|
-
## Rewarded
|
221
|
+
## Rewarded Ads
|
222
|
+
|
223
|
+
> __Note__
|
224
|
+
### Variable name and index (final) cannot be changed.
|
225
|
+
- rewardedAdAdUnitId | index 0
|
226
|
+
- responseInfo | index 1
|
129
227
|
|
130
228
|
```sh
|
131
229
|
|
132
|
-
// Load
|
230
|
+
// Load Rewarded Ad
|
231
|
+
|
232
|
+
let loadRewardedAd = () => {
|
233
|
+
cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
234
|
+
rewardedAdAdUnitId = "ca-app-pub-3940256099942544/5224354917",
|
235
|
+
responseInfo = true, // boolean (debugging)
|
236
|
+
|
237
|
+
|
238
|
+
(info) => { alert(info) },
|
239
|
+
(error) => { alert(error)
|
240
|
+
|
241
|
+
});
|
242
|
+
}
|
243
|
+
|
244
|
+
// call loadRewardedAd();
|
245
|
+
|
246
|
+
// Show Rewarded Ad
|
247
|
+
|
248
|
+
let showRewardedAd = () => {
|
249
|
+
cordova.plugins.emiAdmobPlugin.showRewardedAd();
|
250
|
+
}
|
251
|
+
|
252
|
+
// call showRewardedAd();
|
133
253
|
|
134
|
-
// Show cordova.plugins.emiAdmobPlugin.showRewardedAd();
|
135
254
|
|
136
255
|
```
|
137
256
|
|
138
257
|
[Rewarded ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-rewarded-ads-) - callback:
|
139
258
|
|
140
259
|
|
141
|
-
## Rewarded interstitial
|
260
|
+
## Rewarded interstitial Ads
|
261
|
+
|
262
|
+
> __Note__
|
263
|
+
### Variable name and index (final) cannot be changed.
|
264
|
+
- rewardedInterstitialAdUnitId | index 0
|
265
|
+
- responseInfo | index 1
|
142
266
|
|
143
267
|
```sh
|
144
268
|
|
145
|
-
//
|
269
|
+
// load Rewarded Interstitial Ad
|
146
270
|
|
147
|
-
|
271
|
+
let loadRewardedInterstitialAd = () => {
|
272
|
+
cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
273
|
+
rewardedInterstitialAdUnitId = "ca-app-pub-3940256099942544/5354046379",
|
274
|
+
responseInfo = true, // boolean (debugging)
|
275
|
+
|
276
|
+
(info) => { alert(info) },
|
277
|
+
(error) => { alert(error)
|
148
278
|
|
149
|
-
|
279
|
+
});
|
280
|
+
}
|
150
281
|
|
151
|
-
|
282
|
+
// call loadRewardedInterstitialAd();
|
283
|
+
|
284
|
+
// Show Rewarded Interstitial Ad
|
285
|
+
|
286
|
+
const showRewardedInterstitialAd = () => {
|
287
|
+
cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd();
|
288
|
+
}
|
152
289
|
|
290
|
+
// cal showRewardedInterstitialAd();
|
153
291
|
|
154
292
|
|
293
|
+
```
|
294
|
+
|
295
|
+
[Rewarded interstitial ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-rewarded-ads-) - callback:
|
155
296
|
|
156
297
|
|
157
298
|
|
@@ -167,12 +308,40 @@ alert("on.banner Ad Loaded");
|
|
167
308
|
|
168
309
|
```
|
169
310
|
|
311
|
+
> __Note__
|
312
|
+
### (final) cannot be changed.
|
313
|
+
|
170
314
|
## ( SDK )
|
171
315
|
- on.SdkInitializationComplete
|
172
316
|
|
173
317
|
|
174
318
|
## ( Banner Ads )
|
175
319
|
|
320
|
+
### position
|
321
|
+
|
322
|
+
- top-right
|
323
|
+
- top-center
|
324
|
+
- left
|
325
|
+
- center
|
326
|
+
- right
|
327
|
+
- bottom-center
|
328
|
+
- bottom-right
|
329
|
+
- adaptiveWidth = number
|
330
|
+
> default: 320
|
331
|
+
|
332
|
+
|
333
|
+
### size
|
334
|
+
- Anchored_adaptive
|
335
|
+
- Inline_adaptive
|
336
|
+
- BANNER
|
337
|
+
- LARGE_BANNER
|
338
|
+
- MEDIUM_RECTANGLE
|
339
|
+
- FULL_BANNER
|
340
|
+
- LEADERBOARD
|
341
|
+
- Smart Banners = DEPRECATED
|
342
|
+
- default: Anchored_adaptive
|
343
|
+
|
344
|
+
|
176
345
|
### Event Load a Show
|
177
346
|
|
178
347
|
- on.bannerAdClicked
|
@@ -241,6 +410,15 @@ alert("on.banner Ad Loaded");
|
|
241
410
|
# Admob Mediation
|
242
411
|
<img src="https://user-images.githubusercontent.com/78555833/229587307-91a7e380-aa2d-4140-a62d-fa8e6a8dd153.png" width="500">
|
243
412
|
|
413
|
+
|
414
|
+
## get Mediation Adapter Name
|
415
|
+
|
416
|
+
responseInfo = true // (debugging)
|
417
|
+
|
418
|
+
<img src="https://user-images.githubusercontent.com/78555833/230655800-0dbc3f12-72fb-4cf3-b4e6-801704fade28.png" width="250">
|
419
|
+
|
420
|
+
|
421
|
+
|
244
422
|
## Meta Audience Network
|
245
423
|
|
246
424
|
[Integrate Meta Audience Network with bidding :](https://developers.google.com/admob/android/mediation/meta)
|
@@ -272,6 +450,39 @@ cordova plugin add emi-indo-cordova-plugin-mediation-unity
|
|
272
450
|
cordova plugin add emi-indo-cordova-plugin-mediation-applovin
|
273
451
|
```
|
274
452
|
|
453
|
+
- ================================
|
454
|
+
|
455
|
+
|
456
|
+
## AdColony Ads
|
457
|
+
[Integrate AdColony with Mediation :](https://developers.google.com/admob/android/mediation/adcolony)
|
458
|
+
- (Adapter default: 4.8.0.1)
|
459
|
+
### Installation
|
460
|
+
```sh
|
461
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-adcolony
|
462
|
+
```
|
463
|
+
|
464
|
+
- ================================
|
465
|
+
|
466
|
+
|
467
|
+
## Chartboost Ads
|
468
|
+
[Integrate Chartboost with Mediation :](https://developers.google.com/admob/android/mediation/chartboost)
|
469
|
+
- (Adapter default: 9.2.1.0)
|
470
|
+
### Installation
|
471
|
+
```sh
|
472
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-chartboost
|
473
|
+
```
|
474
|
+
|
475
|
+
- ================================
|
476
|
+
|
477
|
+
|
478
|
+
## ironSource Ads
|
479
|
+
[Integrate ironSource with Mediation :](https://developers.google.com/admob/android/mediation/ironsource)
|
480
|
+
- (Adapter default: 7.2.7.0)
|
481
|
+
### Installation
|
482
|
+
```sh
|
483
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-ironsource
|
484
|
+
```
|
485
|
+
|
275
486
|
|
276
487
|
|
277
488
|
## Variables name or preference name
|
@@ -292,15 +503,28 @@ cordova plugin add emi-indo-cordova-plugin-mediation-meta --variable META_ADAPTE
|
|
292
503
|
- --variable META_ADAPTER_VERSION="xxxxx"
|
293
504
|
- --variable UNITY_ADAPTER_VERSION="xxxxx"
|
294
505
|
- --variable APPLOVIN_ADAPTER_VERSION="xxxxx"
|
506
|
+
- --variable ADCOLONY_ADAPTER_VERSION="xxxxx"
|
507
|
+
- --variable CHARTBOOST_ADAPTER_VERSION="xxxxx"
|
508
|
+
- --variable IRONSOURCE_ADAPTER_VERSION="xxxxx"
|
295
509
|
|
296
510
|
### preference name
|
297
511
|
|
298
512
|
- META_ADAPTER_VERSION
|
299
513
|
- UNITY_ADAPTER_VERSION
|
300
514
|
- APPLOVIN_ADAPTER_VERSION
|
515
|
+
- ADCOLONY_ADAPTER_VERSION
|
516
|
+
- CHARTBOOST_ADAPTER_VERSION
|
517
|
+
- IRONSOURCE_ADAPTER_VERSION
|
518
|
+
|
519
|
+
- ================================
|
520
|
+
|
301
521
|
|
302
522
|
|
303
523
|
|
524
|
+
|
525
|
+
> - ## Note Release
|
526
|
+
[emi-indo-cordova-plugin-admob@0.0.4](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/releases/tag/%400.0.4)
|
527
|
+
|
304
528
|
|
305
529
|
|
306
530
|
### Platform Support
|
package/example/index.html
CHANGED
@@ -7,16 +7,105 @@
|
|
7
7
|
<script>
|
8
8
|
|
9
9
|
|
10
|
-
|
11
|
-
var interstitialAdAdUnitId = "ca-app-pub-3940256099942544/1033173712"
|
12
|
-
var rewardedInterstitialAdUnitId = "ca-app-pub-3940256099942544/5354046379"
|
13
|
-
var rewardedAdAdUnitId = "ca-app-pub-3940256099942544/5224354917"
|
10
|
+
/// setting banner size: BANNER | LARGE_BANNER | MEDIUM_RECTANGLE | FULL_BANNER | LEADERBOARD | default: "BANNER" | (Smart Banners = DEPRECATED) | Inline_adaptive | Anchored_adaptive
|
14
11
|
|
12
|
+
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "bottom-left"
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
|
15
|
+
// Banner Adaptive
|
16
|
+
|
17
|
+
let showBannerAdaptive = () => {
|
18
|
+
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
19
|
+
bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
20
|
+
position = "bottom-center",
|
21
|
+
size = "Inline_adaptive", // | Inline_adaptive | Anchored_adaptive
|
22
|
+
adaptiveWidth = 320,
|
23
|
+
|
24
|
+
(seccess) => { console.log("success") },
|
25
|
+
(error) => { alert(error)
|
26
|
+
|
27
|
+
});
|
28
|
+
}
|
29
|
+
|
30
|
+
// not Adaptive banner
|
31
|
+
|
32
|
+
let showBannerNotAdaptive = () => {
|
33
|
+
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
34
|
+
bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
35
|
+
position = "bottom-center",
|
36
|
+
size = "BANNER",
|
37
|
+
|
38
|
+
(seccess) => { console.log("success") },
|
39
|
+
(error) => { alert(error)
|
40
|
+
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
// Remove Banner
|
45
|
+
|
46
|
+
let removeBannerAd = () => {
|
47
|
+
cordova.plugins.emiAdmobPlugin.removeBannerAd();
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
// Load Interstitial Ad
|
52
|
+
|
53
|
+
let loadInterstitialAd = () => {
|
54
|
+
cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
55
|
+
interstitialAdAdUnitId = "ca-app-pub-3940256099942544/1033173712",
|
56
|
+
responseInfo = true, // boolean
|
57
|
+
|
58
|
+
(info) => { alert(info) },
|
59
|
+
(error) => { alert(error)
|
60
|
+
|
61
|
+
});
|
62
|
+
}
|
63
|
+
|
64
|
+
// Show Interstitial Ad
|
65
|
+
|
66
|
+
let showInterstitialAd = () => {
|
67
|
+
cordova.plugins.emiAdmobPlugin.showInterstitialAd();
|
68
|
+
}
|
69
|
+
|
70
|
+
// load Rewarded Interstitial Ad
|
71
|
+
|
72
|
+
let loadRewardedInterstitialAd = () => {
|
73
|
+
cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
74
|
+
rewardedInterstitialAdUnitId = "ca-app-pub-3940256099942544/5354046379",
|
75
|
+
responseInfo = true, // boolean
|
76
|
+
|
77
|
+
(info) => { alert(info) },
|
78
|
+
(error) => { alert(error)
|
79
|
+
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
// Show Rewarded Interstitial Ad
|
85
|
+
|
86
|
+
const showRewardedInterstitialAd = () => {
|
87
|
+
cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd();
|
88
|
+
}
|
89
|
+
|
90
|
+
// Load Rewarded Ad
|
91
|
+
|
92
|
+
let loadRewardedAd = () => {
|
93
|
+
cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
94
|
+
rewardedAdAdUnitId = "ca-app-pub-3940256099942544/5224354917",
|
95
|
+
responseInfo = true, // boolean
|
96
|
+
|
97
|
+
|
98
|
+
(info) => { alert(info) },
|
99
|
+
(error) => { alert(error)
|
100
|
+
|
101
|
+
});
|
102
|
+
}
|
103
|
+
|
104
|
+
// Show Rewarded Ad
|
105
|
+
|
106
|
+
let showRewardedAd = () => {
|
107
|
+
cordova.plugins.emiAdmobPlugin.showRewardedAd();
|
108
|
+
}
|
20
109
|
|
21
110
|
|
22
111
|
|
@@ -115,18 +204,19 @@ alert("on Rewarded Ad Loaded");
|
|
115
204
|
|
116
205
|
</script>
|
117
206
|
|
118
|
-
<p> <button onclick="
|
119
|
-
<p> <button onclick="
|
207
|
+
<p> <button onclick="showBannerAdaptive();">Show Banner adaptive</button></p>
|
208
|
+
<p> <button onclick="showBannerNotAdaptive();">show Banner No Adaptive</button></p>
|
209
|
+
<p> <button onclick="removeBannerAd();">remove Banner Ad</button></p>
|
120
210
|
|
121
|
-
<p> <button onclick="
|
122
|
-
<p> <button onclick="
|
211
|
+
<p> <button onclick="loadInterstitialAd();">Load Interstitial Ad</button></p>
|
212
|
+
<p> <button onclick="showInterstitialAd();">Show Interstitial Ad</button></p>
|
123
213
|
|
124
|
-
<p> <button onclick="
|
125
|
-
<p> <button onclick="
|
214
|
+
<p> <button onclick="loadRewardedInterstitialAd();">Load Rewarded Interstitial</button></p>
|
215
|
+
<p> <button onclick="showRewardedInterstitialAd();">Show Rewarded Interstitial</button></p>
|
126
216
|
|
127
|
-
<p> <button onclick="
|
128
|
-
<p> <button onclick="
|
217
|
+
<p> <button onclick="loadRewardedAd();">Load Rewarded Ad</button></p>
|
218
|
+
<p> <button onclick="showRewardedAd();">Show Rewarded Ad</button></p>
|
129
219
|
|
130
220
|
|
131
221
|
</body>
|
132
|
-
</html>
|
222
|
+
</html>
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
2
2
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
-
id="emi-indo-cordova-plugin-admob" version="0.0.
|
3
|
+
id="emi-indo-cordova-plugin-admob" version="0.0.5">
|
4
4
|
|
5
5
|
<name>emiAdmobPlugin</name>
|
6
6
|
<description>Cordova Plugin Admob Android</description>
|
@@ -34,7 +34,7 @@
|
|
34
34
|
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
|
35
35
|
|
36
36
|
<preference name="APP_ID_ANDROID" default="ca-app-pub-3940256099942544~3347511713" />
|
37
|
-
<preference name="PLAY_SERVICES_VERSION" default="
|
37
|
+
<preference name="PLAY_SERVICES_VERSION" default="22.0.0" />
|
38
38
|
|
39
39
|
<framework src="com.google.android.gms:play-services-ads:$PLAY_SERVICES_VERSION" />
|
40
40
|
|
@@ -1 +1 @@
|
|
1
|
-
package emi.indo.cordova.plugin.admob;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CallbackContext;import org.apache.cordova.PluginResult;import org.json.JSONArray;import org.json.JSONException;import android.util.Log;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaWebView;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.initialization.InitializationStatus;import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import java.util.Map;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private RelativeLayout bannerViewLayout;private CallbackContext rewardedCallbacks;private AdView bannerView;static boolean isbannerShow=true;static boolean isinterstitialload=false;static boolean isrewardedInterstitialload=false;static boolean isrewardedload=false;public void initialize(CordovaInterface cordova,CordovaWebView webView){super.initialize(cordova,webView);cWebView=webView;}public boolean execute(String action,JSONArray args,final CallbackContext callbackContext)throws JSONException{switch(action){case "initialize":MobileAds.initialize(cordova.getActivity(),initializationStatus ->{Map<String,AdapterStatus> statusMap=initializationStatus.getAdapterStatusMap();for(String adapterClass:statusMap.keySet()){AdapterStatus status=statusMap.get(adapterClass);assert status!=null;callbackContext.success("Adapter name: "+adapterClass+"Description: "+status.getDescription()+"Latency: "+status.getLatency());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.SdkInitializationComplete');");});return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String interstitialAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();InterstitialAd.load(cordova.getActivity(),interstitialAdAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){isinterstitialload=true;mInterstitialAd=interstitialAd;Log.i(TAG,"onAdLoaded");callbackContext.success(interstitialAd.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdLoaded');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());mInterstitialAd=null;isinterstitialload=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdFailedToLoad');");}});});return true;case "showInterstitialAd":if(isinterstitialload){cordova.getActivity().runOnUiThread(()->{mInterstitialAd.show(cordova.getActivity());});}else{callbackContext.error("The Interstitial ad wasn't ready yet");}return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String rewardedAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();RewardedAd.load(cordova.getActivity(),rewardedAdAdUnitId,adRequest,new RewardedAdLoadCallback(){@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedAd=null;isrewardedload=false;Log.d(TAG,"The rewarded ad wasn't ready yet.");callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdFailedToLoad');");}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;isrewardedload=true;Log.d(TAG,"Ad was loaded.");callbackContext.success(ad.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdLoaded');");}});});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedload){rewardedAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String rewardedInterstitialAdUnitId=args.optString(0);RewardedInterstitialAd.load(cordova.getActivity(),rewardedInterstitialAdUnitId,new AdRequest.Builder().build(),new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull RewardedInterstitialAd ad){Log.d(TAG,"Ad was loaded.");rewardedInterstitialAd=ad;isrewardedInterstitialload=true;callbackContext.success(ad.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdLoaded');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedInterstitialAd=null;isrewardedInterstitialload=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdFailedToLoad');");}});});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedInterstitialload){rewardedInterstitialAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{final String bannerAdUnitId=args.optString(0);final String size=args.optString(1);final String position=args.optString(2);if(isbannerShow){if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);bannerViewLayout.setLayoutParams(params);((ViewGroup)Objects.requireNonNull(cWebView.getView())).addView(bannerViewLayout);}bannerView=new AdView(cordova.getActivity());if(Objects.equals(size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else{bannerView.setAdSize(AdSize.BANNER);}bannerView.setAdUnitId(bannerAdUnitId);AdRequest adRequest=new AdRequest.Builder().build();bannerView.loadAd(adRequest);RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}bannerView.setLayoutParams(bannerParams);bannerViewLayout.addView(bannerView);bannerView.setAdListener(new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClicked');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClosed');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError adError){callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdFailedToLoad');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdImpression');");}@Override public void onAdLoaded(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdLoaded');");}@Override public void onAdOpened(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdOpened');");}});}});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;ViewGroup parentView=(ViewGroup)bannerView.getParent();if(parentView!=null){parentView.removeView(bannerView);bannerView.destroy();bannerView=null;isbannerShow=true;}else{isbannerShow=true;}});return true;}mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdShowedFullScreenContent');");}});rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdShowedFullScreenContent');");}});rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdShowedFullScreenContent');");}});return false;}}
|
1
|
+
package emi.indo.cordova.plugin.admob;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CallbackContext;import org.json.JSONArray;import org.json.JSONException;import android.util.Log;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaWebView;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.ResponseInfo;import com.google.android.gms.ads.VersionInfo;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import com.google.android.ump.ConsentForm;import com.google.android.ump.ConsentInformation;import com.google.android.ump.ConsentRequestParameters;import com.google.android.ump.FormError;import com.google.android.ump.UserMessagingPlatform;import java.util.Map;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private RelativeLayout bannerViewLayout;private CallbackContext rewardedCallbacks;private AdView bannerView;static boolean isbannerDestroy=false;static boolean isbannerShow=true;static boolean isinterstitialload=false;static boolean isrewardedInterstitialload=false;static boolean isrewardedload=false;private ConsentInformation consentInformation;private ConsentForm consentForm;public void initialize(CordovaInterface cordova,CordovaWebView webView){super.initialize(cordova,webView);cWebView=webView;}public boolean execute(String action,JSONArray args,final CallbackContext callbackContext)throws JSONException{switch(action){case "initialize":VersionInfo mobileAds=MobileAds.getVersion();MobileAds.initialize(cordova.getActivity(),initializationStatus ->{Map<String,AdapterStatus> statusMap=initializationStatus.getAdapterStatusMap();for(String adapterClass:statusMap.keySet()){AdapterStatus status=statusMap.get(adapterClass);if(status!=null){Log.d(TAG,String.format("Adapter name:%s,Description:%s,Latency:%d",adapterClass,status.getDescription(),status.getLatency()));}}callbackContext.success(mobileAds.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.SdkInitializationComplete');");});return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String interstitialAdAdUnitId=args.optString(0);final boolean responseInfo=args.optBoolean(1);AdRequest adRequest=new AdRequest.Builder().build();InterstitialAd.load(cordova.getActivity(),interstitialAdAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){isinterstitialload=true;mInterstitialAd=interstitialAd;Log.i(TAG,"onAdLoaded");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdLoaded');");if(responseInfo){ResponseInfo responseInfo=interstitialAd.getResponseInfo();callbackContext.success(responseInfo.toString());}}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdFailedToLoad');");callbackContext.error(loadAdError.toString());}});});return true;case "showInterstitialAd":if(isinterstitialload){cordova.getActivity().runOnUiThread(()->{mInterstitialAd.show(cordova.getActivity());});}else{callbackContext.error("The Interstitial ad wasn't ready yet");}return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String rewardedAdAdUnitId=args.optString(0);final boolean responseInfo=args.optBoolean(1);AdRequest adRequest=new AdRequest.Builder().build();RewardedAd.load(cordova.getActivity(),rewardedAdAdUnitId,adRequest,new RewardedAdLoadCallback(){@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedAd=null;isrewardedload=false;Log.d(TAG,"The rewarded ad wasn't ready yet.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdFailedToLoad');");callbackContext.error(loadAdError.toString());}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;isrewardedload=true;Log.d(TAG,"Ad was loaded.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdLoaded');");if(responseInfo){ResponseInfo responseInfo=ad.getResponseInfo();callbackContext.success(responseInfo.toString());}}});});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedload){rewardedAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String rewardedInterstitialAdUnitId=args.optString(0);final boolean responseInfo=args.optBoolean(1);RewardedInterstitialAd.load(cordova.getActivity(),rewardedInterstitialAdUnitId,new AdRequest.Builder().build(),new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull RewardedInterstitialAd ad){Log.d(TAG,"Ad was loaded.");rewardedInterstitialAd=ad;isrewardedInterstitialload=true;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdLoaded');");if(responseInfo){ResponseInfo responseInfo=ad.getResponseInfo();callbackContext.success(responseInfo.toString());}}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdFailedToLoad');");callbackContext.error(loadAdError.toString());}});});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedInterstitialload){rewardedInterstitialAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{final String bannerAdUnitId=args.optString(0);final String position=args.optString(1);final String size=args.optString(2);final int adaptiveWidth=args.optInt(3);if(isbannerShow){if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);bannerViewLayout.setLayoutParams(params);((ViewGroup)Objects.requireNonNull(cWebView.getView())).addView(bannerViewLayout);}bannerView=new AdView(cordova.getActivity());if(Objects.equals(size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else if(Objects.equals(size,"Anchored_adaptive")){bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),adaptiveWidth));}else if(Objects.equals(size,"Inline_adaptive")){bannerView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(cordova.getActivity(),adaptiveWidth));}else{bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),320));}bannerView.setAdUnitId(bannerAdUnitId);AdRequest adRequest=new AdRequest.Builder().build();bannerView.loadAd(adRequest);isbannerShow=false;RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}isbannerDestroy=true;bannerView.setLayoutParams(bannerParams);bannerViewLayout.addView(bannerView);bannerView.setAdListener(new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClicked');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClosed');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdFailedToLoad');");callbackContext.error(adError.toString());}@Override public void onAdImpression(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdImpression');");}@Override public void onAdLoaded(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdLoaded');");}@Override public void onAdOpened(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdOpened');");}});}});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(isbannerDestroy){if(bannerView==null)return;RelativeLayout bannerViewLayout=(RelativeLayout)bannerView.getParent();if(bannerViewLayout!=null){bannerViewLayout.removeView(bannerView);bannerView.destroy();bannerView=null;isbannerDestroy=false;isbannerShow=true;}}});return true;case "getConsentRequest":final boolean setTagForUnderAgeOfConsent=args.optBoolean(0);cordova.getActivity().runOnUiThread(()->{ConsentRequestParameters params=new ConsentRequestParameters .Builder().setTagForUnderAgeOfConsent(setTagForUnderAgeOfConsent).build();consentInformation=UserMessagingPlatform.getConsentInformation(cordova.getActivity());consentInformation.requestConsentInfoUpdate(cordova.getActivity(),params,()->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onConsentInfoUpdateSuccess');");if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.NOT_REQUIRED){callbackContext.success(ConsentInformation.ConsentStatus.NOT_REQUIRED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.ConsentStatus.NOT_REQUIRED');");}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.OBTAINED){callbackContext.success(ConsentInformation.ConsentStatus.OBTAINED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.ConsentStatus.OBTAINED');");}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.REQUIRED){callbackContext.success(ConsentInformation.ConsentStatus.REQUIRED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.ConsentStatus.REQUIRED');");if(consentInformation.isConsentFormAvailable()){UserMessagingPlatform.loadConsentForm(cordova.getContext(),consentForm ->{consentForm.show(cordova.getActivity(),formError ->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.ShowError');");callbackContext.error(String.valueOf(formError));});},formError -> callbackContext.error(formError.getMessage()));cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.loadConsentFormError');");}else{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.ConsentFormNotAvailable');");}}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.UNKNOWN){callbackContext.success(ConsentInformation.ConsentStatus.UNKNOWN);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.ConsentStatus.UNKNOWN');");}},formError ->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onConsentInfoUpdateFailure');");callbackContext.error(formError.getMessage());});});return true;case "consentReset":cordova.getActivity().runOnUiThread(()->{consentInformation.reset();});return true;}mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");mInterstitialAd=null;isinterstitialload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdShowedFullScreenContent');");}});rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedAd=null;isrewardedload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdShowedFullScreenContent');");}});rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedInterstitialAd=null;isrewardedInterstitialload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdShowedFullScreenContent');");}});return false;}public void onDestroy(){if(bannerView!=null){bannerView.destroy();isbannerDestroy=false;isbannerShow=true;}}}
|
package/www/emiAdmobPlugin.js
CHANGED
@@ -1,38 +1,45 @@
|
|
1
1
|
var exec = require('cordova/exec');
|
2
2
|
|
3
|
-
|
4
3
|
exports.initialize = function (arg0, success, error) {
|
5
4
|
exec(success, error, 'emiAdmobPlugin', 'initialize', [arg0]);
|
6
5
|
};
|
7
6
|
|
8
|
-
exports.showBannerAd = function (
|
9
|
-
exec(success, error, 'emiAdmobPlugin', 'showBannerAd', [
|
7
|
+
exports.showBannerAd = function (arg0, arg1, arg2, arg3, success, error) {
|
8
|
+
exec(success, error, 'emiAdmobPlugin', 'showBannerAd', [arg0, arg1, arg2, arg3]);
|
10
9
|
};
|
11
10
|
|
12
11
|
exports.removeBannerAd = function (arg0, success, error) {
|
13
12
|
exec(success, error, 'emiAdmobPlugin', 'removeBannerAd', [arg0]);
|
14
13
|
};
|
15
14
|
|
16
|
-
exports.loadInterstitialAd = function (arg0, success, error) {
|
17
|
-
exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0]);
|
15
|
+
exports.loadInterstitialAd = function (arg0, arg1, success, error) {
|
16
|
+
exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0, arg1]);
|
18
17
|
};
|
19
18
|
|
20
19
|
exports.showInterstitialAd = function (arg0, success, error) {
|
21
20
|
exec(success, error, 'emiAdmobPlugin', 'showInterstitialAd', [arg0]);
|
22
21
|
};
|
23
22
|
|
24
|
-
exports.loadRewardedAd = function (arg0, success, error) {
|
25
|
-
exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0]);
|
23
|
+
exports.loadRewardedAd = function (arg0, arg1, success, error) {
|
24
|
+
exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0, arg1]);
|
26
25
|
};
|
27
26
|
|
28
27
|
exports.showRewardedAd = function (arg0, success, error) {
|
29
28
|
exec(success, error, 'emiAdmobPlugin', 'showRewardedAd', [arg0]);
|
30
29
|
};
|
31
30
|
|
32
|
-
exports.loadRewardedInterstitialAd = function (arg0, success, error) {
|
33
|
-
exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0]);
|
31
|
+
exports.loadRewardedInterstitialAd = function (arg0, arg1, success, error) {
|
32
|
+
exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0, arg1]);
|
34
33
|
};
|
35
34
|
|
36
35
|
exports.showRewardedInterstitialAd = function (arg0, success, error) {
|
37
36
|
exec(success, error, 'emiAdmobPlugin', 'showRewardedInterstitialAd', [arg0]);
|
37
|
+
};
|
38
|
+
|
39
|
+
exports.getConsentRequest = function (arg0, success, error) {
|
40
|
+
exec(success, error, 'emiAdmobPlugin', 'getConsentRequest', [arg0]);
|
41
|
+
};
|
42
|
+
|
43
|
+
exports.consentReset = function (arg0, success, error) {
|
44
|
+
exec(success, error, 'emiAdmobPlugin', 'consentReset', [arg0]);
|
38
45
|
};
|