emi-indo-cordova-plugin-admob 0.0.9 → 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 +151 -25
- package/example/index.html +55 -13
- package/package.json +1 -1
- package/plugin.xml +2 -2
- package/src/android/emiAdmobPlugin.java +1 -1
- package/www/emiAdmobPlugin.js +4 -0
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,14 @@
|
|
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
|
+
|
28
|
+
|
29
|
+
## Features
|
34
30
|
|
31
|
+
- SDK initialize
|
32
|
+
- targeting
|
33
|
+
- globalSettings
|
35
34
|
- App Open Ads
|
36
35
|
- Banner Ads
|
37
36
|
- Interstitial Ads
|
@@ -44,6 +43,9 @@
|
|
44
43
|
- App Open Ads ( Finished )
|
45
44
|
- User Consent ( Finished ) [emi-indo-cordova-plugin-consent](https://github.com/EMI-INDO/emi-indo-cordova-plugin-consent)
|
46
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
|
47
49
|
|
48
50
|
|
49
51
|
## Installation
|
@@ -99,9 +101,91 @@ cordova plugin add emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-ap
|
|
99
101
|
"mediation_group_name": "Campaign"
|
100
102
|
}
|
101
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
|
+
|
102
112
|
```
|
103
113
|
|
104
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
|
+
|
105
189
|
## deviceready
|
106
190
|
|
107
191
|
[Example ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/index.html) - index.html:
|
@@ -112,7 +196,39 @@ cordova plugin add emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-ap
|
|
112
196
|
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
113
197
|
// This needs to be done only once, ideally at app launch.
|
114
198
|
|
115
|
-
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
|
+
});
|
116
232
|
|
117
233
|
document.addEventListener('on.SdkInitializationComplete', () => {
|
118
234
|
|
@@ -128,7 +244,7 @@ alert("on Sdk Initialization Complete");
|
|
128
244
|
|
129
245
|
> __Note__
|
130
246
|
### Variable name and index (final) cannot be changed.
|
131
|
-
-
|
247
|
+
- AdUnitId | index 0
|
132
248
|
- npa | index 1
|
133
249
|
- responseInfo | index 2
|
134
250
|
|
@@ -137,10 +253,10 @@ alert("on Sdk Initialization Complete");
|
|
137
253
|
|
138
254
|
let loadAppOpenAd = () => {
|
139
255
|
cordova.plugins.emiAdmobPlugin.loadAppOpenAd(
|
140
|
-
|
256
|
+
AdUnitId = "ca-app-pub-3940256099942544/3419835294",
|
141
257
|
npa = "1", // String | 0 | 1
|
142
258
|
responseInfo = true, // boolean
|
143
|
-
|
259
|
+
// Optional
|
144
260
|
(info) => { alert(info) },
|
145
261
|
(error) => { alert(error)
|
146
262
|
|
@@ -164,7 +280,7 @@ let showAppOpenAd = () => {
|
|
164
280
|
|
165
281
|
> __Note__
|
166
282
|
### Variable name and index (final) cannot be changed.
|
167
|
-
-
|
283
|
+
- AdUnitId | index 0
|
168
284
|
- npa | index 1
|
169
285
|
- position | index 2
|
170
286
|
- size | index 3
|
@@ -206,13 +322,14 @@ default: "bottom-left"
|
|
206
322
|
|
207
323
|
let showBannerAdaptive = () => {
|
208
324
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
209
|
-
|
325
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
210
326
|
npa = "1", // String | 0 | 1
|
211
327
|
position = "bottom-center",
|
212
328
|
size = "Anchored_FULL_WIDTH", // | Inline_adaptive | Anchored_adaptive
|
213
329
|
adaptiveWidth = 320,
|
214
330
|
responseInfo = true, // boolean (debugging)
|
215
331
|
|
332
|
+
// Optional
|
216
333
|
(info) => { alert(info) },
|
217
334
|
(error) => { alert(error)
|
218
335
|
|
@@ -225,12 +342,13 @@ let showBannerAdaptive = () => {
|
|
225
342
|
|
226
343
|
let showBannerNotAdaptive = () => {
|
227
344
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
228
|
-
|
345
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
229
346
|
npa = "1", // String | 0 | 1
|
230
347
|
position = "bottom-center",
|
231
348
|
size = "FLUID",
|
232
349
|
responseInfo = true, // boolean (debugging)
|
233
350
|
|
351
|
+
// Optional
|
234
352
|
(info) => { alert(info) },
|
235
353
|
(error) => { alert(error)
|
236
354
|
|
@@ -255,7 +373,7 @@ let removeBannerAd = () => {
|
|
255
373
|
|
256
374
|
> __Note__
|
257
375
|
### Variable name and index (final) cannot be changed.
|
258
|
-
-
|
376
|
+
- AdUnitId | index 0
|
259
377
|
- npa | index 1
|
260
378
|
- responseInfo | index 2
|
261
379
|
|
@@ -264,10 +382,11 @@ let removeBannerAd = () => {
|
|
264
382
|
|
265
383
|
let loadInterstitialAd = () => {
|
266
384
|
cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
267
|
-
|
385
|
+
AdUnitId = "ca-app-pub-3940256099942544/1033173712",
|
268
386
|
npa = "1", // String | 0 | 1
|
269
387
|
responseInfo = true, // boolean (debugging)
|
270
|
-
|
388
|
+
|
389
|
+
// Optional
|
271
390
|
(info) => { alert(info) },
|
272
391
|
(error) => { alert(error)
|
273
392
|
|
@@ -294,7 +413,7 @@ let showInterstitialAd = () => {
|
|
294
413
|
|
295
414
|
> __Note__
|
296
415
|
### Variable name and index (final) cannot be changed.
|
297
|
-
-
|
416
|
+
- AdUnitId | index 0
|
298
417
|
- npa | index 1
|
299
418
|
- responseInfo | index 2
|
300
419
|
|
@@ -304,10 +423,10 @@ let showInterstitialAd = () => {
|
|
304
423
|
|
305
424
|
let loadRewardedAd = () => {
|
306
425
|
cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
307
|
-
|
426
|
+
AdUnitId = "ca-app-pub-3940256099942544/5224354917",
|
308
427
|
npa = "1", // String | 0 | 1
|
309
428
|
responseInfo = true, // boolean (debugging)
|
310
|
-
|
429
|
+
// Optional
|
311
430
|
(info) => { alert(info) },
|
312
431
|
(error) => { alert(error)
|
313
432
|
|
@@ -334,7 +453,7 @@ let showRewardedAd = () => {
|
|
334
453
|
|
335
454
|
> __Note__
|
336
455
|
### Variable name and index (final) cannot be changed.
|
337
|
-
-
|
456
|
+
- AdUnitId | index 0
|
338
457
|
- npa | index 1
|
339
458
|
- responseInfo | index 2
|
340
459
|
|
@@ -344,10 +463,10 @@ let showRewardedAd = () => {
|
|
344
463
|
|
345
464
|
let loadRewardedInterstitialAd = () => {
|
346
465
|
cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
347
|
-
|
466
|
+
AdUnitId = "ca-app-pub-3940256099942544/5354046379",
|
348
467
|
npa = "1", // String | 0 | 1
|
349
468
|
responseInfo = true, // boolean (debugging)
|
350
|
-
|
469
|
+
// Optional
|
351
470
|
(info) => { alert(info) },
|
352
471
|
(error) => { alert(error)
|
353
472
|
|
@@ -653,4 +772,11 @@ emi-indo-cordova-plugin-admob@0.0.5
|
|
653
772
|
- ### emi-indo-cordova-plugin-open-ai
|
654
773
|
|
655
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:
|
656
782
|
|
package/example/index.html
CHANGED
@@ -11,11 +11,12 @@
|
|
11
11
|
|
12
12
|
let loadAppOpenAd = () => {
|
13
13
|
cordova.plugins.emiAdmobPlugin.loadAppOpenAd(
|
14
|
-
|
14
|
+
AdUnitId = "ca-app-pub-3940256099942544/3419835294",
|
15
15
|
npa = "1", // String | 0 | 1
|
16
16
|
responseInfo = true, // boolean
|
17
17
|
|
18
|
-
|
18
|
+
// Optional
|
19
|
+
(info) => { alert(info) },
|
19
20
|
(error) => { alert(error)
|
20
21
|
|
21
22
|
});
|
@@ -60,14 +61,15 @@ default: "bottom-left"
|
|
60
61
|
|
61
62
|
let showBannerAdaptive = () => {
|
62
63
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
63
|
-
|
64
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
64
65
|
npa = "1", // String | 0 | 1
|
65
66
|
position = "bottom-center",
|
66
67
|
size = "Anchored_FULL_WIDTH", // | Inline_adaptive | Anchored_adaptive | default: Anchored_FULL_WIDTH
|
67
68
|
adaptiveWidth = 320,
|
68
69
|
responseInfo = true, // boolean
|
69
70
|
|
70
|
-
|
71
|
+
// Optional
|
72
|
+
(info) => { alert(info) },
|
71
73
|
(error) => { alert(error)
|
72
74
|
|
73
75
|
});
|
@@ -77,13 +79,15 @@ let showBannerAdaptive = () => {
|
|
77
79
|
|
78
80
|
let showBannerNotAdaptive = () => {
|
79
81
|
cordova.plugins.emiAdmobPlugin.showBannerAd(
|
80
|
-
|
82
|
+
AdUnitId = "ca-app-pub-3940256099942544/6300978111",
|
81
83
|
npa = "1", // String | 0 | 1
|
82
84
|
position = "bottom-center",
|
83
85
|
size = "FLUID",
|
86
|
+
adaptiveWidth = 320,
|
84
87
|
responseInfo = true, // boolean
|
85
88
|
|
86
|
-
|
89
|
+
// Optional
|
90
|
+
(info) => { alert(info) },
|
87
91
|
(error) => { alert(error)
|
88
92
|
|
89
93
|
});
|
@@ -100,11 +104,12 @@ let removeBannerAd = () => {
|
|
100
104
|
|
101
105
|
let loadInterstitialAd = () => {
|
102
106
|
cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
103
|
-
|
107
|
+
AdUnitId = "ca-app-pub-3940256099942544/1033173712",
|
104
108
|
npa = "1", // String | 0 | 1
|
105
109
|
responseInfo = true, // boolean
|
106
110
|
|
107
|
-
|
111
|
+
// Optional
|
112
|
+
(info) => { alert(info) },
|
108
113
|
(error) => { alert(error)
|
109
114
|
|
110
115
|
});
|
@@ -120,11 +125,12 @@ let showInterstitialAd = () => {
|
|
120
125
|
|
121
126
|
let loadRewardedInterstitialAd = () => {
|
122
127
|
cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
123
|
-
|
128
|
+
AdUnitId = "ca-app-pub-3940256099942544/5354046379",
|
124
129
|
npa = "1", // String | 0 | 1
|
125
130
|
responseInfo = true, // boolean
|
126
131
|
|
127
|
-
|
132
|
+
// Optional
|
133
|
+
(info) => { alert(info) },
|
128
134
|
(error) => { alert(error)
|
129
135
|
|
130
136
|
});
|
@@ -141,11 +147,11 @@ const showRewardedInterstitialAd = () => {
|
|
141
147
|
|
142
148
|
let loadRewardedAd = () => {
|
143
149
|
cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
144
|
-
|
150
|
+
AdUnitId = "ca-app-pub-3940256099942544/5224354917",
|
145
151
|
npa = "1", // String | 0 | 1
|
146
152
|
responseInfo = true, // boolean
|
147
153
|
|
148
|
-
|
154
|
+
// Optional
|
149
155
|
(info) => { alert(info) },
|
150
156
|
(error) => { alert(error)
|
151
157
|
|
@@ -165,7 +171,43 @@ document.addEventListener("deviceready", function(){
|
|
165
171
|
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
166
172
|
// This needs to be done only once, ideally at app launch.
|
167
173
|
|
168
|
-
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
|
+
|
169
211
|
|
170
212
|
document.addEventListener('on.SdkInitializationComplete', () => {
|
171
213
|
|
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.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.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;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":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 "loadAppOpenAd":cordova.getActivity().runOnUiThread(()->{final String appOpenAdUnitId=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();AppOpenAd.load(cordova.getContext(),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());}}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){isAppOpenAdShow=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.open.failed.loaded');");}});});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 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){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(bannerAdUnitId);Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);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){try{ResponseInfo responseInfo=bannerView.getResponseInfo();assert responseInfo!=null;callbackContext.success(responseInfo.toString());}catch(NullPointerException e){e.printStackTrace();}}}@Override public void onAdOpened(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdOpened');");}});});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":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;}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;}@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();}}
|
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
@@ -54,4 +54,8 @@ exports.consentReset = function (arg0, success, error) {
|
|
54
54
|
|
55
55
|
exports.targeting = function (arg0, arg1, arg2, success, error) {
|
56
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]);
|
57
61
|
};
|