emi-indo-cordova-plugin-admob 0.0.8 → 1.0.9
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 +209 -23
- package/example/index.html +95 -11
- package/package.json +1 -1
- package/plugin.xml +2 -2
- package/src/android/emiAdmobPlugin.java +1 -1
- package/www/emiAdmobPlugin.js +14 -3
package/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# emi-indo-cordova-plugin-admob
|
2
2
|
Cordova Plugin Admob Android and IOS
|
3
3
|
|
4
|
-
### Mobile Ads SDK (Android: 22.
|
4
|
+
### Mobile Ads SDK (Android: 22.1.0) [Release Notes:](https://developers.google.com/admob/android/rel-notes)
|
5
5
|
|
6
6
|
### Mobile Ads SDK (IOS: 10.3.0) [Release Notes:](https://developers.google.com/admob/ios/rel-notes)
|
7
7
|
|
@@ -10,13 +10,6 @@
|
|
10
10
|
-
|
11
11
|
|
12
12
|
|
13
|
-
> __Warning__
|
14
|
-
> 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
|
15
|
-
|
16
|
-
> __Warning__
|
17
|
-
> 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.
|
18
|
-
|
19
|
-
|
20
13
|
> __Note__
|
21
14
|
> - ## It's Not a fork, it's purely rewritten, clean of 3rd party code.
|
22
15
|
|
@@ -30,8 +23,15 @@
|
|
30
23
|
## 💰Sponsor this project
|
31
24
|
[](https://paypal.me/emiindo)
|
32
25
|
|
33
|
-
|
26
|
+
## [Check all release notes:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/releases/)
|
27
|
+
|
34
28
|
|
29
|
+
## Features
|
30
|
+
|
31
|
+
- SDK initialize
|
32
|
+
- targeting
|
33
|
+
- globalSettings
|
34
|
+
- App Open Ads
|
35
35
|
- Banner Ads
|
36
36
|
- Interstitial Ads
|
37
37
|
- Rewarded Ads
|
@@ -40,9 +40,12 @@
|
|
40
40
|
- Mediation
|
41
41
|
|
42
42
|
## Coming soon
|
43
|
-
- App Open Ads
|
43
|
+
- App Open Ads ( Finished )
|
44
44
|
- User Consent ( Finished ) [emi-indo-cordova-plugin-consent](https://github.com/EMI-INDO/emi-indo-cordova-plugin-consent)
|
45
45
|
- Mediation ( Finished )
|
46
|
+
- https://developers.google.com/admob/android/native/start
|
47
|
+
- https://developers.google.com/admob/android/impression-level-ad-revenue
|
48
|
+
- https://developers.google.com/admob/android/ssv
|
46
49
|
|
47
50
|
|
48
51
|
## Installation
|
@@ -98,9 +101,91 @@ cordova plugin add emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-ap
|
|
98
101
|
"mediation_group_name": "Campaign"
|
99
102
|
}
|
100
103
|
}
|
104
|
+
|
105
|
+
|
106
|
+
Bundle[{max_ad_content_rating=G,
|
107
|
+
npa=1,
|
108
|
+
is_designed_for_families=0,
|
109
|
+
under_age_of_consent=0]
|
110
|
+
|
111
|
+
|
101
112
|
```
|
102
113
|
|
103
114
|
|
115
|
+
### As suggested by Google, when the SDK initializes this plugin automatically takes the Global Settings and Targeting values.
|
116
|
+
|
117
|
+
### Global Settings
|
118
|
+
```sh
|
119
|
+
// Instruction: https://developers.google.com/admob/android/global-settings
|
120
|
+
|
121
|
+
cordova.plugins.emiAdmobPlugin.globalSettings(
|
122
|
+
|
123
|
+
setAppMuted = true, // Type Boolean default: true
|
124
|
+
setAppVolume = 1.0, // Type float
|
125
|
+
enableSameAppKey = false, // Type Boolean default: false
|
126
|
+
|
127
|
+
// Optional
|
128
|
+
(info) => { alert(info) },
|
129
|
+
(error) => { alert(error)
|
130
|
+
|
131
|
+
});
|
132
|
+
```
|
133
|
+
|
134
|
+
### Targeting
|
135
|
+
|
136
|
+
> __Note__
|
137
|
+
> - ## You can see the value when the ad is loaded, set responseInfo = true
|
138
|
+
|
139
|
+
```sh
|
140
|
+
// Instruction: https://developers.google.com/admob/android/targeting
|
141
|
+
// Overview: https://developers.google.com/android/reference/com/google/android/gms/ads/RequestConfiguration
|
142
|
+
|
143
|
+
cordova.plugins.emiAdmobPlugin.targeting(
|
144
|
+
TagForChildDirectedTreatment = 0, // value: 0 | -1 | 1
|
145
|
+
TagForUnderAgeOfConsent = 0, // // value: 0 | -1 | 1
|
146
|
+
MaxAdContentRating = "G", // value: G | MA | PG | T | ""
|
147
|
+
|
148
|
+
// Optional
|
149
|
+
(info) => { alert(info) },
|
150
|
+
(error) => { alert(error)
|
151
|
+
|
152
|
+
});
|
153
|
+
|
154
|
+
|
155
|
+
// (TagForChildDirectedTreatment)
|
156
|
+
// Type number:
|
157
|
+
// value: 0 | -1 | 1
|
158
|
+
// (value description)
|
159
|
+
// 0 = FALSE
|
160
|
+
// 1 = TRUE
|
161
|
+
// -1 = UNSPECIFIED
|
162
|
+
// (if else/undefined = false/0)
|
163
|
+
|
164
|
+
///////////////////////////////
|
165
|
+
|
166
|
+
// (TagForUnderAgeOfConsent)
|
167
|
+
// Type number:
|
168
|
+
// value: 0 | -1 | 1
|
169
|
+
// (value description)
|
170
|
+
// 0 = FALSE
|
171
|
+
// 1 = TRUE
|
172
|
+
// -1 = UNSPECIFIED
|
173
|
+
// (if else/undefined = false/0)
|
174
|
+
|
175
|
+
//////////////////////////////
|
176
|
+
|
177
|
+
// (MaxAdContentRating)
|
178
|
+
// Type String:
|
179
|
+
// value: G | MA | PG | T | ""
|
180
|
+
// (value description)
|
181
|
+
// https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/max-ad-content-rating
|
182
|
+
// (if else/undefined/"" = NULL)
|
183
|
+
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
|
104
189
|
## deviceready
|
105
190
|
|
106
191
|
[Example ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/index.html) - index.html:
|
@@ -111,7 +196,39 @@ cordova plugin add emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-ap
|
|
111
196
|
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
112
197
|
// This needs to be done only once, ideally at app launch.
|
113
198
|
|
114
|
-
cordova.plugins.emiAdmobPlugin.initialize(
|
199
|
+
cordova.plugins.emiAdmobPlugin.initialize(
|
200
|
+
// Optional
|
201
|
+
(info) => { alert(info) },
|
202
|
+
(error) => { alert(error)
|
203
|
+
|
204
|
+
});
|
205
|
+
|
206
|
+
|
207
|
+
//(Auto Loaded during SDK initialize and ad loaded)
|
208
|
+
|
209
|
+
cordova.plugins.emiAdmobPlugin.targeting(
|
210
|
+
TagForChildDirectedTreatment = 0, // value: 0 | -1 | 1
|
211
|
+
TagForUnderAgeOfConsent = 0, // // value: 0 | -1 | 1
|
212
|
+
MaxAdContentRating = "G", // value: G | MA | PG | T | ""
|
213
|
+
|
214
|
+
// Optional
|
215
|
+
(info) => { console.log(info)},
|
216
|
+
(error) => { alert(error)
|
217
|
+
|
218
|
+
});
|
219
|
+
|
220
|
+
|
221
|
+
cordova.plugins.emiAdmobPlugin.globalSettings(
|
222
|
+
|
223
|
+
setAppMuted = true, // Type Boolean default: true
|
224
|
+
setAppVolume = 1.0, // Type float
|
225
|
+
enableSameAppKey = false, // Type Boolean default: false
|
226
|
+
|
227
|
+
// Optional
|
228
|
+
(info) => { console.log(info) },
|
229
|
+
(error) => { alert(error)
|
230
|
+
|
231
|
+
});
|
115
232
|
|
116
233
|
document.addEventListener('on.SdkInitializationComplete', () => {
|
117
234
|
|
@@ -122,11 +239,48 @@ alert("on Sdk Initialization Complete");
|
|
122
239
|
|
123
240
|
```
|
124
241
|
|
242
|
+
|
243
|
+
## App Open Ads
|
244
|
+
|
245
|
+
> __Note__
|
246
|
+
### Variable name and index (final) cannot be changed.
|
247
|
+
- AdUnitId | index 0
|
248
|
+
- npa | index 1
|
249
|
+
- responseInfo | index 2
|
250
|
+
|
251
|
+
```sh
|
252
|
+
// load App Open Ad
|
253
|
+
|
254
|
+
let loadAppOpenAd = () => {
|
255
|
+
cordova.plugins.emiAdmobPlugin.loadAppOpenAd(
|
256
|
+
AdUnitId = "ca-app-pub-3940256099942544/3419835294",
|
257
|
+
npa = "1", // String | 0 | 1
|
258
|
+
responseInfo = true, // boolean
|
259
|
+
// Optional
|
260
|
+
(info) => { alert(info) },
|
261
|
+
(error) => { alert(error)
|
262
|
+
|
263
|
+
});
|
264
|
+
}
|
265
|
+
|
266
|
+
// call loadAppOpenAd();
|
267
|
+
|
268
|
+
// Show App Open Ad
|
269
|
+
|
270
|
+
let showAppOpenAd = () => {
|
271
|
+
cordova.plugins.emiAdmobPlugin.showAppOpenAd();
|
272
|
+
}
|
273
|
+
|
274
|
+
// call showAppOpenAd();
|
275
|
+
|
276
|
+
```
|
277
|
+
|
278
|
+
|
125
279
|
## Banner Ads
|
126
280
|
|
127
281
|
> __Note__
|
128
282
|
### Variable name and index (final) cannot be changed.
|
129
|
-
-
|
283
|
+
- AdUnitId | index 0
|
130
284
|
- npa | index 1
|
131
285
|
- position | index 2
|
132
286
|
- size | index 3
|
@@ -168,13 +322,14 @@ default: "bottom-left"
|
|
168
322
|
|
169
323
|
let showBannerAdaptive = () => {
|
170
324
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
171
|
-
|
325
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
172
326
|
npa = "1", // String | 0 | 1
|
173
327
|
position = "bottom-center",
|
174
328
|
size = "Anchored_FULL_WIDTH", // | Inline_adaptive | Anchored_adaptive
|
175
329
|
adaptiveWidth = 320,
|
176
330
|
responseInfo = true, // boolean (debugging)
|
177
331
|
|
332
|
+
// Optional
|
178
333
|
(info) => { alert(info) },
|
179
334
|
(error) => { alert(error)
|
180
335
|
|
@@ -187,12 +342,13 @@ let showBannerAdaptive = () => {
|
|
187
342
|
|
188
343
|
let showBannerNotAdaptive = () => {
|
189
344
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
190
|
-
|
345
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
191
346
|
npa = "1", // String | 0 | 1
|
192
347
|
position = "bottom-center",
|
193
348
|
size = "FLUID",
|
194
349
|
responseInfo = true, // boolean (debugging)
|
195
350
|
|
351
|
+
// Optional
|
196
352
|
(info) => { alert(info) },
|
197
353
|
(error) => { alert(error)
|
198
354
|
|
@@ -217,7 +373,7 @@ let removeBannerAd = () => {
|
|
217
373
|
|
218
374
|
> __Note__
|
219
375
|
### Variable name and index (final) cannot be changed.
|
220
|
-
-
|
376
|
+
- AdUnitId | index 0
|
221
377
|
- npa | index 1
|
222
378
|
- responseInfo | index 2
|
223
379
|
|
@@ -226,10 +382,11 @@ let removeBannerAd = () => {
|
|
226
382
|
|
227
383
|
let loadInterstitialAd = () => {
|
228
384
|
cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
229
|
-
|
385
|
+
AdUnitId = "ca-app-pub-3940256099942544/1033173712",
|
230
386
|
npa = "1", // String | 0 | 1
|
231
387
|
responseInfo = true, // boolean (debugging)
|
232
|
-
|
388
|
+
|
389
|
+
// Optional
|
233
390
|
(info) => { alert(info) },
|
234
391
|
(error) => { alert(error)
|
235
392
|
|
@@ -256,7 +413,7 @@ let showInterstitialAd = () => {
|
|
256
413
|
|
257
414
|
> __Note__
|
258
415
|
### Variable name and index (final) cannot be changed.
|
259
|
-
-
|
416
|
+
- AdUnitId | index 0
|
260
417
|
- npa | index 1
|
261
418
|
- responseInfo | index 2
|
262
419
|
|
@@ -266,10 +423,10 @@ let showInterstitialAd = () => {
|
|
266
423
|
|
267
424
|
let loadRewardedAd = () => {
|
268
425
|
cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
269
|
-
|
426
|
+
AdUnitId = "ca-app-pub-3940256099942544/5224354917",
|
270
427
|
npa = "1", // String | 0 | 1
|
271
428
|
responseInfo = true, // boolean (debugging)
|
272
|
-
|
429
|
+
// Optional
|
273
430
|
(info) => { alert(info) },
|
274
431
|
(error) => { alert(error)
|
275
432
|
|
@@ -296,7 +453,7 @@ let showRewardedAd = () => {
|
|
296
453
|
|
297
454
|
> __Note__
|
298
455
|
### Variable name and index (final) cannot be changed.
|
299
|
-
-
|
456
|
+
- AdUnitId | index 0
|
300
457
|
- npa | index 1
|
301
458
|
- responseInfo | index 2
|
302
459
|
|
@@ -306,10 +463,10 @@ let showRewardedAd = () => {
|
|
306
463
|
|
307
464
|
let loadRewardedInterstitialAd = () => {
|
308
465
|
cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
309
|
-
|
466
|
+
AdUnitId = "ca-app-pub-3940256099942544/5354046379",
|
310
467
|
npa = "1", // String | 0 | 1
|
311
468
|
responseInfo = true, // boolean (debugging)
|
312
|
-
|
469
|
+
// Optional
|
313
470
|
(info) => { alert(info) },
|
314
471
|
(error) => { alert(error)
|
315
472
|
|
@@ -352,6 +509,20 @@ alert("on.banner Ad Loaded");
|
|
352
509
|
- on.SdkInitializationComplete
|
353
510
|
|
354
511
|
|
512
|
+
## ( App Open Ads )
|
513
|
+
|
514
|
+
### Event Load
|
515
|
+
|
516
|
+
- on.open.loaded
|
517
|
+
- on.open.failed.loaded
|
518
|
+
|
519
|
+
### Event Show
|
520
|
+
|
521
|
+
- on.open.dismissed
|
522
|
+
- on.open.failed.show
|
523
|
+
- on.open.show
|
524
|
+
|
525
|
+
|
355
526
|
## ( Banner Ads )
|
356
527
|
|
357
528
|
### position
|
@@ -367,9 +538,11 @@ alert("on.banner Ad Loaded");
|
|
367
538
|
|
368
539
|
|
369
540
|
### size
|
541
|
+
|
370
542
|
- Anchored_adaptive
|
371
543
|
- Inline_adaptive
|
372
544
|
- BANNER
|
545
|
+
- FLUID
|
373
546
|
- LARGE_BANNER
|
374
547
|
- MEDIUM_RECTANGLE
|
375
548
|
- FULL_BANNER
|
@@ -593,4 +766,17 @@ emi-indo-cordova-plugin-admob@0.0.5
|
|
593
766
|
- ### emi-indo-cordova-plugin-unityads
|
594
767
|
|
595
768
|
[Cordova Plugin Unity:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-unityads) - Ads:
|
769
|
+
|
770
|
+
## New Open AI
|
771
|
+
|
772
|
+
- ### emi-indo-cordova-plugin-open-ai
|
773
|
+
|
774
|
+
[Cordova Plugin Open Ai:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-open-ai) - Open AI:
|
775
|
+
|
776
|
+
|
777
|
+
## New Firebase Analytics
|
778
|
+
|
779
|
+
- ### emi-indo-cordova-plugin-fanalytics
|
780
|
+
|
781
|
+
[Cordova Plugin Firebase Analytics:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-fanalytics) - Firebase Analytics:
|
596
782
|
|
package/example/index.html
CHANGED
@@ -7,6 +7,28 @@
|
|
7
7
|
<script>
|
8
8
|
|
9
9
|
|
10
|
+
// load App Open Ad
|
11
|
+
|
12
|
+
let loadAppOpenAd = () => {
|
13
|
+
cordova.plugins.emiAdmobPlugin.loadAppOpenAd(
|
14
|
+
AdUnitId = "ca-app-pub-3940256099942544/3419835294",
|
15
|
+
npa = "1", // String | 0 | 1
|
16
|
+
responseInfo = true, // boolean
|
17
|
+
|
18
|
+
// Optional
|
19
|
+
(info) => { alert(info) },
|
20
|
+
(error) => { alert(error)
|
21
|
+
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
// Show App Open Ad
|
26
|
+
|
27
|
+
let showAppOpenAd = () => {
|
28
|
+
cordova.plugins.emiAdmobPlugin.showAppOpenAd();
|
29
|
+
}
|
30
|
+
|
31
|
+
|
10
32
|
/// setting banner size:
|
11
33
|
/*
|
12
34
|
BANNER
|
@@ -39,14 +61,15 @@ default: "bottom-left"
|
|
39
61
|
|
40
62
|
let showBannerAdaptive = () => {
|
41
63
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
42
|
-
|
64
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
43
65
|
npa = "1", // String | 0 | 1
|
44
66
|
position = "bottom-center",
|
45
67
|
size = "Anchored_FULL_WIDTH", // | Inline_adaptive | Anchored_adaptive | default: Anchored_FULL_WIDTH
|
46
68
|
adaptiveWidth = 320,
|
47
69
|
responseInfo = true, // boolean
|
48
70
|
|
49
|
-
|
71
|
+
// Optional
|
72
|
+
(info) => { alert(info) },
|
50
73
|
(error) => { alert(error)
|
51
74
|
|
52
75
|
});
|
@@ -56,13 +79,15 @@ let showBannerAdaptive = () => {
|
|
56
79
|
|
57
80
|
let showBannerNotAdaptive = () => {
|
58
81
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
59
|
-
|
82
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
60
83
|
npa = "1", // String | 0 | 1
|
61
84
|
position = "bottom-center",
|
62
85
|
size = "FLUID",
|
86
|
+
adaptiveWidth = 320,
|
63
87
|
responseInfo = true, // boolean
|
64
88
|
|
65
|
-
|
89
|
+
// Optional
|
90
|
+
(info) => { alert(info) },
|
66
91
|
(error) => { alert(error)
|
67
92
|
|
68
93
|
});
|
@@ -79,11 +104,12 @@ let removeBannerAd = () => {
|
|
79
104
|
|
80
105
|
let loadInterstitialAd = () => {
|
81
106
|
cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
82
|
-
|
107
|
+
AdUnitId = "ca-app-pub-3940256099942544/1033173712",
|
83
108
|
npa = "1", // String | 0 | 1
|
84
109
|
responseInfo = true, // boolean
|
85
110
|
|
86
|
-
|
111
|
+
// Optional
|
112
|
+
(info) => { alert(info) },
|
87
113
|
(error) => { alert(error)
|
88
114
|
|
89
115
|
});
|
@@ -99,11 +125,12 @@ let showInterstitialAd = () => {
|
|
99
125
|
|
100
126
|
let loadRewardedInterstitialAd = () => {
|
101
127
|
cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
102
|
-
|
128
|
+
AdUnitId = "ca-app-pub-3940256099942544/5354046379",
|
103
129
|
npa = "1", // String | 0 | 1
|
104
130
|
responseInfo = true, // boolean
|
105
131
|
|
106
|
-
|
132
|
+
// Optional
|
133
|
+
(info) => { alert(info) },
|
107
134
|
(error) => { alert(error)
|
108
135
|
|
109
136
|
});
|
@@ -120,11 +147,11 @@ const showRewardedInterstitialAd = () => {
|
|
120
147
|
|
121
148
|
let loadRewardedAd = () => {
|
122
149
|
cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
123
|
-
|
150
|
+
AdUnitId = "ca-app-pub-3940256099942544/5224354917",
|
124
151
|
npa = "1", // String | 0 | 1
|
125
152
|
responseInfo = true, // boolean
|
126
153
|
|
127
|
-
|
154
|
+
// Optional
|
128
155
|
(info) => { alert(info) },
|
129
156
|
(error) => { alert(error)
|
130
157
|
|
@@ -144,7 +171,43 @@ document.addEventListener("deviceready", function(){
|
|
144
171
|
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
145
172
|
// This needs to be done only once, ideally at app launch.
|
146
173
|
|
147
|
-
cordova.plugins.emiAdmobPlugin.initialize(
|
174
|
+
cordova.plugins.emiAdmobPlugin.initialize(
|
175
|
+
// Optional
|
176
|
+
(info) => { console.log(info) },
|
177
|
+
(error) => { alert(error)
|
178
|
+
|
179
|
+
});
|
180
|
+
|
181
|
+
// Instruction: https://developers.google.com/admob/android/global-settings
|
182
|
+
|
183
|
+
cordova.plugins.emiAdmobPlugin.globalSettings(
|
184
|
+
|
185
|
+
setAppMuted = true, // Type Boolean default: true
|
186
|
+
setAppVolume = 1.0, // Type float
|
187
|
+
enableSameAppKey = false, // Type Boolean default: false
|
188
|
+
|
189
|
+
// Optional
|
190
|
+
(info) => { console.log(info) },
|
191
|
+
(error) => { alert(error)
|
192
|
+
|
193
|
+
});
|
194
|
+
|
195
|
+
|
196
|
+
// You can see the value when the ad is loaded, set responseInfo = true
|
197
|
+
// Instruction: https://developers.google.com/admob/android/targeting
|
198
|
+
// Overview: https://developers.google.com/android/reference/com/google/android/gms/ads/RequestConfiguration
|
199
|
+
|
200
|
+
cordova.plugins.emiAdmobPlugin.targeting(
|
201
|
+
TagForChildDirectedTreatment = 0, // value: 0 | -1 | 1
|
202
|
+
TagForUnderAgeOfConsent = 0, // // value: 0 | -1 | 1
|
203
|
+
MaxAdContentRating = "G", // value: G | MA | PG | T | ""
|
204
|
+
|
205
|
+
// Optional
|
206
|
+
(info) => { console.log(info) },
|
207
|
+
(error) => { alert(error)
|
208
|
+
|
209
|
+
});
|
210
|
+
|
148
211
|
|
149
212
|
document.addEventListener('on.SdkInitializationComplete', () => {
|
150
213
|
|
@@ -153,6 +216,24 @@ alert("on Sdk Initialization Complete");
|
|
153
216
|
|
154
217
|
});
|
155
218
|
|
219
|
+
// AppOpenAd EVEN
|
220
|
+
|
221
|
+
/*
|
222
|
+
on.open.loaded
|
223
|
+
on.open.failed.loaded
|
224
|
+
on.open.dismissed
|
225
|
+
on.open.failed.show
|
226
|
+
on.open.show
|
227
|
+
*/
|
228
|
+
|
229
|
+
|
230
|
+
document.addEventListener('on.open.loaded', () => {
|
231
|
+
|
232
|
+
alert("on app open loaded");
|
233
|
+
|
234
|
+
});
|
235
|
+
|
236
|
+
|
156
237
|
|
157
238
|
// BANNER EVENT
|
158
239
|
|
@@ -236,6 +317,9 @@ alert("on Rewarded Ad Loaded");
|
|
236
317
|
|
237
318
|
</script>
|
238
319
|
|
320
|
+
<p> <button onclick="loadAppOpenAd();">load App Open Ad</button></p>
|
321
|
+
<p> <button onclick="showAppOpenAd();">Show App Open Ad</button></p>
|
322
|
+
|
239
323
|
<p> <button onclick="showBannerAdaptive();">Show Banner adaptive</button></p>
|
240
324
|
<p> <button onclick="showBannerNotAdaptive();">show Banner No Adaptive</button></p>
|
241
325
|
<p> <button onclick="removeBannerAd();">remove Banner Ad</button></p>
|
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="
|
3
|
+
id="emi-indo-cordova-plugin-admob" version="1.0.9">
|
4
4
|
|
5
5
|
<name>emiAdmobPlugin</name>
|
6
6
|
<description>Cordova Plugin Admob Android</description>
|
@@ -36,7 +36,7 @@
|
|
36
36
|
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
|
37
37
|
|
38
38
|
<preference name="APP_ID_ANDROID" default="ca-app-pub-3940256099942544~3347511713" />
|
39
|
-
<preference name="PLAY_SERVICES_VERSION" default="22.
|
39
|
+
<preference name="PLAY_SERVICES_VERSION" default="22.1.0" />
|
40
40
|
|
41
41
|
<framework src="com.google.android.gms:play-services-ads:$PLAY_SERVICES_VERSION" />
|
42
42
|
|
@@ -1 +1 @@
|
|
1
|
-
package emi.indo.cordova.plugin.admob;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.LinearLayout;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import com.google.ads.mediation.admob.AdMobAdapter;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdListener;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.MobileAds;import com.google.android.gms.ads.RequestConfiguration;import com.google.android.gms.ads.ResponseInfo;import com.google.android.gms.ads.VersionInfo;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;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.UserMessagingPlatform;import org.apache.cordova.CallbackContext;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CordovaWebView;import org.json.JSONArray;import org.json.JSONException;import java.util.Map;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private ViewGroup parentView;private AdView adView;private RelativeLayout adViewLayout=null;private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private 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 "targeting":cordova.getActivity().runOnUiThread(()->{final boolean TagForChildDirectedTreatment=args.optBoolean(0);final boolean TagForUnderAgeOfConsent=args.optBoolean(1);final String MaxAdContentRating=args.optString(2);if(TagForChildDirectedTreatment){RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE).build();MobileAds.setRequestConfiguration(requestConfiguration);}else{RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE).build();MobileAds.setRequestConfiguration(requestConfiguration);}if(TagForUnderAgeOfConsent){RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE).build();MobileAds.setRequestConfiguration(requestConfiguration);}else{RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE).build();MobileAds.setRequestConfiguration(requestConfiguration);}if(Objects.equals(MaxAdContentRating,"G")){RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G).build();MobileAds.setRequestConfiguration(requestConfiguration);}else if(Objects.equals(MaxAdContentRating,"MA")){RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_MA).build();MobileAds.setRequestConfiguration(requestConfiguration);}else if(Objects.equals(MaxAdContentRating,"PG")){RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_PG).build();MobileAds.setRequestConfiguration(requestConfiguration);}else if(Objects.equals(MaxAdContentRating,"T")){RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_T).build();MobileAds.setRequestConfiguration(requestConfiguration);}else{RequestConfiguration requestConfiguration=MobileAds.getRequestConfiguration().toBuilder().setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED).build();MobileAds.setRequestConfiguration(requestConfiguration);}});return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String interstitialAdAdUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).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 String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedAd.load(cordova.getActivity(),rewardedAdAdUnitId,adRequest,new RewardedAdLoadCallback(){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();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.rewarded');");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 String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedInterstitialAd.load(cordova.getActivity(),rewardedInterstitialAdUnitId,adRequest,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();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitial.rewarded');");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 npa=args.optString(1);final String position=args.optString(2);final String size=args.optString(3);final int adaptiveWidth=args.optInt(4);final boolean responseInfo=args.optBoolean(5);if(isbannerShow){adView=new AdView(cordova.getActivity());if(Objects.equals(size,"BANNER")){adView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){adView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){adView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){adView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){adView.setAdSize(AdSize.LEADERBOARD);}else if(Objects.equals(size,"FLUID")){adView.setAdSize(AdSize.FLUID);}else if(Objects.equals(size,"Anchored_adaptive")){adView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),adaptiveWidth));}else if(Objects.equals(size,"Inline_adaptive")){adView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(cordova.getActivity(),adaptiveWidth));}else{adView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),AdSize.FULL_WIDTH));}adView.setAdUnitId(bannerAdUnitId);Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();adView.loadAd(adRequest);isbannerShow=false;if(adView.getParent()!=null){((ViewGroup)adView.getParent()).removeView(adView);}if(isbannerShow){RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,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;}if(adViewLayout==null){adViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams Params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);try{((ViewGroup)(((View)Objects.requireNonNull(webView.getClass().getMethod("getView").invoke(webView))).getParent())).addView(adViewLayout,Params);}catch(Exception e){((ViewGroup)webView).addView(adViewLayout,Params);}}adViewLayout.addView(adView,bannerParams);adViewLayout.bringToFront();}else{ViewGroup wvParentView=(ViewGroup)getWebView().getParent();if(parentView==null){parentView=new LinearLayout(webView.getContext());}if(wvParentView!=null&&wvParentView!=parentView){ViewGroup rootView=(ViewGroup)(getWebView().getParent());wvParentView.removeView(getWebView());((LinearLayout)parentView).setOrientation(LinearLayout.VERTICAL);parentView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT,0.0F));getWebView().setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT,1.0F));parentView.addView(getWebView());rootView.addView(parentView);}if(isbannerShow){RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,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;}adViewLayout.addView(adView,bannerParams);}else{parentView.addView(adView);}parentView.bringToFront();parentView.requestLayout();parentView.requestFocus();}}adView.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(){if(responseInfo){try{ResponseInfo responseInfo=adView.getResponseInfo();assert responseInfo!=null;callbackContext.success(responseInfo.toString());}catch(NullPointerException e){e.printStackTrace();}}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(adView!=null){ViewGroup parentView=(ViewGroup)adView.getParent();if(parentView!=null){parentView.removeView(adView);}adView.destroy();adView=null;}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(adView!=null){adView.destroy();adView=null;}if(adViewLayout!=null){ViewGroup parentView=(ViewGroup)adViewLayout.getParent();if(parentView!=null){parentView.removeView(adViewLayout);}adViewLayout=null;}}private View getWebView(){try{return(View)webView.getClass().getMethod("getView").invoke(webView);}catch(Exception e){return(View)webView;}}}
|
1
|
+
package emi.indo.cordova.plugin.admob;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import com.google.ads.mediation.admob.AdMobAdapter;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdListener;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.MobileAds;import com.google.android.gms.ads.RequestConfiguration;import com.google.android.gms.ads.ResponseInfo;import com.google.android.gms.ads.appopen.AppOpenAd;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;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.UserMessagingPlatform;import org.apache.cordova.CallbackContext;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CordovaWebView;import org.json.JSONArray;import org.json.JSONException;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 AppOpenAd appOpenAd=null;private boolean isAppOpenAdShow=false;private boolean isbannerShow=true;static boolean isinterstitialload=false;static boolean isrewardedInterstitialload=false;static boolean isrewardedload=false;static boolean isonPaidEvent=false;int SetTagForChildDirectedTreatment;int SetTagForUnderAgeOfConsent;String SetMaxAdContentRating;String appOpenAdUnitId;String bannerAdUnitId;String interstitialAdUnitId;String rewardedInterstitialAdUnitId;String rewardedAdUnitId;boolean SetAppMuted;float SetAppVolume;boolean EnableSameAppKey;private ConsentInformation consentInformation;private ConsentForm consentForm;private RelativeLayout bannerViewLayout;private AdView bannerView;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":Log.d(TAG,"SDK Version: "+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){_globalSettings();_Targeting();Log.d(TAG,String.format("Adapter name:%s,Description:%s,Latency:%d",adapterClass,status.getDescription(),status.getLatency()));}}callbackContext.success("SDK Version: "+MobileAds.getVersion().toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.SdkInitializationComplete');");});return true;case "targeting":cordova.getActivity().runOnUiThread(()->{final int TagForChildDirectedTreatment=args.optInt(0);final int TagForUnderAgeOfConsent=args.optInt(1);final String MaxAdContentRating=args.optString(2);try{this.SetTagForChildDirectedTreatment=TagForChildDirectedTreatment;this.SetTagForUnderAgeOfConsent=TagForUnderAgeOfConsent;this.SetMaxAdContentRating=MaxAdContentRating;}catch(Exception e){callbackContext.error(e.toString());}});return true;case "globalSettings":cordova.getActivity().runOnUiThread(()->{final boolean setAppMuted=args.optBoolean(0);final float setAppVolume=(float)args.optDouble(1);final boolean enableSameAppKey=args.optBoolean(2);try{this.SetAppMuted=setAppMuted;this.SetAppVolume=setAppVolume;this.EnableSameAppKey=enableSameAppKey;}catch(Exception e){callbackContext.error(e.toString());}});return true;case "loadAppOpenAd":cordova.getActivity().runOnUiThread(()->{final String AdUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.appOpenAdUnitId=AdUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();AppOpenAd.load(cordova.getContext(),this.appOpenAdUnitId,adRequest,new AppOpenAd.AppOpenAdLoadCallback(){@Override public void onAdLoaded(@NonNull AppOpenAd ad){appOpenAd=ad;isAppOpenAdShow=true;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.open.loaded');");if(responseInfo){ResponseInfo responseInfo=appOpenAd.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){isAppOpenAdShow=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.open.failed.loaded');");}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showAppOpenAd":if(isAppOpenAdShow){cordova.getActivity().runOnUiThread(()-> appOpenAd.show(cordova.getActivity()));}else{callbackContext.error("The App Open Ad wasn't ready yet");}return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String AdUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.interstitialAdUnitId=AdUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();InterstitialAd.load(cordova.getActivity(),this.interstitialAdUnitId,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()+ '\n'+'\n'+bundleExtra);}}@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());}});}catch(Exception e){callbackContext.error(e.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 AdUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.rewardedAdUnitId=AdUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedAd.load(cordova.getActivity(),this.rewardedAdUnitId,adRequest,new RewardedAdLoadCallback(){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()+ '\n'+'\n'+bundleExtra);}}});}catch(Exception e){callbackContext.error(e.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();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.rewarded');");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 AdUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.rewardedInterstitialAdUnitId=AdUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedInterstitialAd.load(cordova.getActivity(),this.rewardedInterstitialAdUnitId,adRequest,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()+ '\n'+'\n'+bundleExtra);}}@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());}});}catch(Exception e){callbackContext.error(e.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();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitial.rewarded');");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 AdUnitId=args.optString(0);final String npa=args.optString(1);final String position=args.optString(2);final String size=args.optString(3);final int adaptiveWidth=args.optInt(4);final boolean responseInfo=args.optBoolean(5);try{this.bannerAdUnitId=AdUnitId;if(isbannerShow){if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);bannerViewLayout.setLayoutParams(params);try{((ViewGroup)(((View)Objects.requireNonNull(webView.getClass().getMethod("getView").invoke(webView))).getParent())).addView(bannerViewLayout,params);}catch(Exception e){((ViewGroup)webView).addView(bannerViewLayout,params);}}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,"FLUID")){bannerView.setAdSize(AdSize.FLUID);}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(),AdSize.FULL_WIDTH));}bannerView.setAdUnitId(this.bannerAdUnitId);Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).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;}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');");if(responseInfo){Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",SetMaxAdContentRating);try{ResponseInfo responseInfo=bannerView.getResponseInfo();assert responseInfo!=null;callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}catch(NullPointerException e){e.printStackTrace();}}}@Override public void onAdOpened(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdOpened');");}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;RelativeLayout bannerViewLayout=(RelativeLayout)bannerView.getParent();if(bannerViewLayout!=null){bannerViewLayout.removeView(bannerView);bannerView.destroy();bannerView=null;isbannerShow=true;}});return true;case "getConsentRequest":cordova.getActivity().runOnUiThread(()->{try{ConsentRequestParameters params=new ConsentRequestParameters .Builder().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());});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "consentReset":cordova.getActivity().runOnUiThread(()-> consentInformation.reset());return true;}appOpenAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdDismissedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.open.dismissed');");appOpenAd=null;}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.open.failed.show');");callbackContext.error(adError.toString());appOpenAd=null;}@Override public void onAdShowedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.open.show');");}});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 _globalSettings(){MobileAds.setAppMuted(this.SetAppMuted);MobileAds.setAppVolume(this.SetAppVolume);MobileAds.enableSameAppKey(this.EnableSameAppKey);}public void _Targeting(){RequestConfiguration.Builder requestConfiguration=MobileAds.getRequestConfiguration().toBuilder();if(SetTagForChildDirectedTreatment==-1){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);}else if(SetTagForChildDirectedTreatment==0){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);}else if(SetTagForChildDirectedTreatment==1){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE);}else{requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);}if(SetTagForUnderAgeOfConsent==-1){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}else if(SetTagForUnderAgeOfConsent==0){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);}else if(SetTagForUnderAgeOfConsent==1){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE);}else{requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}if(Objects.equals(SetMaxAdContentRating,"")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED);}else if(Objects.equals(SetMaxAdContentRating,"T")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_T);}else if(Objects.equals(SetMaxAdContentRating,"PG")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_PG);}else if(Objects.equals(SetMaxAdContentRating,"MA")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_MA);}else if(Objects.equals(SetMaxAdContentRating,"G")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G);}else{requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}MobileAds.setRequestConfiguration(requestConfiguration.build());}@Override public void onDestroy(){if(bannerView!=null){bannerView.destroy();bannerView=null;}if(bannerViewLayout!=null){ViewGroup parentView=(ViewGroup)bannerViewLayout.getParent();if(parentView!=null){parentView.removeView(bannerViewLayout);}bannerViewLayout=null;}super.onDestroy();}}
|
package/www/emiAdmobPlugin.js
CHANGED
@@ -1,12 +1,19 @@
|
|
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.
|
9
|
-
exec(success, error, 'emiAdmobPlugin', '
|
7
|
+
exports.loadAppOpenAd = function (arg0, arg1, arg2, success, error) {
|
8
|
+
exec(success, error, 'emiAdmobPlugin', 'loadAppOpenAd', [arg0, arg1, arg2]);
|
9
|
+
};
|
10
|
+
|
11
|
+
exports.showAppOpenAd = function (arg0, success, error) {
|
12
|
+
exec(success, error, 'emiAdmobPlugin', 'showAppOpenAd', [arg0]);
|
13
|
+
};
|
14
|
+
|
15
|
+
exports.showBannerAd = function (arg0, arg1, arg2, arg3, arg4, arg5, success, error) {
|
16
|
+
exec(success, error, 'emiAdmobPlugin', 'showBannerAd', [arg0, arg1, arg2, arg3, arg4, arg5]);
|
10
17
|
};
|
11
18
|
|
12
19
|
exports.removeBannerAd = function (arg0, success, error) {
|
@@ -47,4 +54,8 @@ exports.consentReset = function (arg0, success, error) {
|
|
47
54
|
|
48
55
|
exports.targeting = function (arg0, arg1, arg2, success, error) {
|
49
56
|
exec(success, error, 'emiAdmobPlugin', 'targeting', [arg0, arg1, arg2]);
|
57
|
+
};
|
58
|
+
|
59
|
+
exports.globalSettings = function (arg0, arg1, arg2, success, error) {
|
60
|
+
exec(success, error, 'emiAdmobPlugin', 'globalSettings', [arg0, arg1, arg2]);
|
50
61
|
};
|