emi-indo-cordova-plugin-admob 0.0.2 → 0.0.4
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 +231 -63
- package/example/getMediationAdapterName.html +59 -0
- package/example/index.html +131 -111
- package/package.json +1 -1
- package/plugin.xml +2 -2
- package/src/android/emiAdmobPlugin.java +1 -1
- package/www/emiAdmobPlugin.js +2 -2
package/README.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# emi-indo-cordova-plugin-admob
|
2
2
|
Cordova Plugin Admob Android
|
3
3
|
|
4
|
-
### Mobile Ads SDK (Android:
|
4
|
+
### Mobile Ads SDK (Android: 22.0.0)
|
5
|
+
[Release Notes:](https://developers.google.com/admob/android/rel-notes)
|
5
6
|
|
7
|
+
> __Warning__
|
8
|
+
> Updating the Mobile Ads SDK version may cause some code to malfunction, as the latest version usually deprecates some older code, [scrrenshot](https://drive.google.com/file/d/1UKaEjdmGRXgdZ2DKfOne8BSq13IUY14_/view) Current plugin code SDK 22.0.0
|
6
9
|
|
7
10
|
> __Warning__
|
8
|
-
>
|
11
|
+
> If the cordova admob plugin using Mobile Ads SDK code version 20.6.0 is upgraded to Mobile Ads SDK version 22.0.0, some of the old plugin code will not work.
|
12
|
+
|
9
13
|
|
10
14
|
> __Note__
|
11
15
|
> - ## It's Not a fork, it's purely rewritten, clean of 3rd party code.
|
@@ -34,7 +38,7 @@ https://user-images.githubusercontent.com/78555833/228323239-e9e18e74-b814-4ca8-
|
|
34
38
|
## Coming soon
|
35
39
|
- App Open Ads
|
36
40
|
- User Consent
|
37
|
-
- Mediation
|
41
|
+
- Mediation ( In the process )
|
38
42
|
|
39
43
|
|
40
44
|
## Installation
|
@@ -51,49 +55,84 @@ cordova plugin add https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob --v
|
|
51
55
|
cordova plugin rm emi-indo-cordova-plugin-admob
|
52
56
|
```
|
53
57
|
|
58
|
+
## Upgrade Mobile Ads SDK
|
59
|
+
[Release Notes Mobile Ads SDK:](https://developers.google.com/admob/android/rel-notes)
|
60
|
+
```sh
|
61
|
+
cordova plugin add https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713 --variable PLAY_SERVICES_VERSION="xxxx"
|
62
|
+
```
|
63
|
+
|
64
|
+
|
65
|
+
|
54
66
|
## 💰Sponsor this project
|
55
67
|
[](https://paypal.me/emiindo)
|
56
68
|
|
57
69
|
## deviceready
|
58
70
|
|
59
|
-
|
60
|
-
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
61
|
-
// This needs to be done only once, ideally at app launch.
|
71
|
+
[Example ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/index.html) - index.html:
|
62
72
|
|
63
|
-
cordova.plugins.emiAdmobPlugin.initialize();
|
64
73
|
|
65
|
-
document.addEventListener('onInitializationComplete', () => {
|
66
74
|
|
67
|
-
alert("on Initialization Complete");
|
68
75
|
|
69
|
-
|
76
|
+
```sh
|
70
77
|
|
78
|
+
/*
|
79
|
+
( set banner size: )
|
71
80
|
|
72
|
-
|
73
|
-
|
81
|
+
Anchored_adaptive
|
82
|
+
Inline_adaptive
|
83
|
+
BANNER
|
84
|
+
LARGE_BANNER
|
85
|
+
MEDIUM_RECTANGLE
|
86
|
+
FULL_BANNER
|
87
|
+
LEADERBOARD
|
88
|
+
Smart Banners = DEPRECATED
|
89
|
+
default: Anchored_adaptive
|
74
90
|
|
75
|
-
```sh
|
76
|
-
var AdUnitId = {
|
77
91
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
92
|
+
( set banner position )
|
93
|
+
|
94
|
+
top-right
|
95
|
+
top-center
|
96
|
+
left
|
97
|
+
center
|
98
|
+
right
|
99
|
+
bottom-center
|
100
|
+
bottom-right
|
101
|
+
|
102
|
+
adaptiveWidth = 320 // default: 320
|
103
|
+
*/
|
82
104
|
|
83
105
|
|
84
|
-
|
106
|
+
var bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111"
|
107
|
+
var interstitialAdAdUnitId = "ca-app-pub-3940256099942544/1033173712"
|
108
|
+
var rewardedInterstitialAdUnitId = "ca-app-pub-3940256099942544/5354046379"
|
109
|
+
var rewardedAdAdUnitId = "ca-app-pub-3940256099942544/5224354917"
|
85
110
|
|
86
|
-
|
87
|
-
var size = "LARGE_BANNER"
|
88
|
-
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "" = bottom-left
|
111
|
+
var size = "Anchored_adaptive"
|
89
112
|
var position = "bottom-center"
|
113
|
+
var adaptiveWidth = 320
|
90
114
|
|
91
115
|
|
92
|
-
//
|
93
|
-
//
|
116
|
+
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
117
|
+
// This needs to be done only once, ideally at app launch.
|
118
|
+
|
119
|
+
cordova.plugins.emiAdmobPlugin.initialize();
|
120
|
+
|
121
|
+
document.addEventListener('on.SdkInitializationComplete', () => {
|
122
|
+
|
123
|
+
alert("on Sdk Initialization Complete");
|
124
|
+
|
125
|
+
});
|
126
|
+
|
94
127
|
|
95
128
|
```
|
96
129
|
|
130
|
+
## Banner Ads
|
131
|
+
```sh
|
132
|
+
// Load a Show BANNER cordova.plugins.emiAdmobPlugin.showBannerAd(bannerAdUnitId, size, position);
|
133
|
+
// Load a Show BANNER adaptive cordova.plugins.emiAdmobPlugin.showBannerAd(bannerAdUnitId, size, position, adaptiveWidth);
|
134
|
+
// remove cordova.plugins.emiAdmobPlugin.removeBannerAd();
|
135
|
+
```
|
97
136
|
[Banner ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-banner-ads-) - callback:
|
98
137
|
|
99
138
|
|
@@ -101,11 +140,11 @@ var position = "bottom-center"
|
|
101
140
|
|
102
141
|
```sh
|
103
142
|
|
104
|
-
// Load cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
143
|
+
// Load cordova.plugins.emiAdmobPlugin.loadInterstitialAd(interstitialAdAdUnitId);
|
105
144
|
|
106
145
|
// Show cordova.plugins.emiAdmobPlugin.showInterstitialAd();
|
107
|
-
|
108
146
|
```
|
147
|
+
|
109
148
|
[Interstitial ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-interstitial-ads-) - callback:
|
110
149
|
|
111
150
|
|
@@ -114,7 +153,7 @@ var position = "bottom-center"
|
|
114
153
|
|
115
154
|
```sh
|
116
155
|
|
117
|
-
// Load cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
156
|
+
// Load cordova.plugins.emiAdmobPlugin.loadRewardedAd(rewardedAdAdUnitId);
|
118
157
|
|
119
158
|
// Show cordova.plugins.emiAdmobPlugin.showRewardedAd();
|
120
159
|
|
@@ -127,7 +166,7 @@ var position = "bottom-center"
|
|
127
166
|
|
128
167
|
```sh
|
129
168
|
|
130
|
-
// Load cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
169
|
+
// Load cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(rewardedInterstitialAdUnitId);
|
131
170
|
|
132
171
|
// Show cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd();
|
133
172
|
|
@@ -136,87 +175,206 @@ var position = "bottom-center"
|
|
136
175
|
[Rewarded interstitial ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-rewarded-ads-) - callback:
|
137
176
|
|
138
177
|
|
178
|
+
## handle success or error
|
139
179
|
|
180
|
+
[Example code ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/getMediationAdapterName.html)
|
181
|
+
```sh
|
140
182
|
|
183
|
+
cordova.plugins.emiAdmobPlugin.loadRewardedAd(rewardedAdAdUnitId, success, error);
|
184
|
+
|
185
|
+
```
|
141
186
|
|
142
187
|
|
143
188
|
# Event | callback:
|
144
189
|
### event code
|
145
190
|
|
146
191
|
```sh
|
147
|
-
document.addEventListener('
|
192
|
+
document.addEventListener('on.bannerAdLoaded', () => {
|
148
193
|
|
149
|
-
alert("on Ad Loaded
|
194
|
+
alert("on.banner Ad Loaded");
|
150
195
|
|
151
196
|
});
|
152
197
|
|
153
198
|
```
|
154
199
|
|
155
|
-
## (
|
200
|
+
## ( SDK )
|
201
|
+
- on.SdkInitializationComplete
|
202
|
+
|
203
|
+
|
204
|
+
## ( Banner Ads )
|
205
|
+
|
206
|
+
### size
|
207
|
+
- Anchored_adaptive
|
208
|
+
- Inline_adaptive
|
209
|
+
- BANNER
|
210
|
+
- LARGE_BANNER
|
211
|
+
- MEDIUM_RECTANGLE
|
212
|
+
- FULL_BANNER
|
213
|
+
- LEADERBOARD
|
214
|
+
- Smart Banners = DEPRECATED
|
215
|
+
- default: Anchored_adaptive
|
156
216
|
|
157
|
-
### Event Show a load
|
158
217
|
|
159
|
-
|
160
|
-
- onAdClosed.bannerAd
|
161
|
-
- onAdFailedToLoad.bannerAd
|
162
|
-
- onAdImpression.bannerAd
|
163
|
-
- onAdLoaded.bannerAd
|
164
|
-
- onAdOpened.bannerAd
|
218
|
+
### position
|
165
219
|
|
220
|
+
- top-right
|
221
|
+
- top-center
|
222
|
+
- left
|
223
|
+
- center
|
224
|
+
- right
|
225
|
+
- bottom-center
|
226
|
+
- bottom-right
|
227
|
+
- adaptiveWidth = number
|
228
|
+
> default: 320
|
166
229
|
|
167
230
|
|
231
|
+
### Event Load a Show
|
168
232
|
|
169
|
-
|
233
|
+
- on.bannerAdClicked
|
234
|
+
- on.bannerAdClosed
|
235
|
+
- on.bannerAdFailedToLoad
|
236
|
+
- on.bannerAdImpression
|
237
|
+
- on.bannerAdLoaded
|
238
|
+
- on.bannerAdOpened
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
## ( Interstitial Ads )
|
170
244
|
|
171
245
|
### Event Load
|
172
246
|
|
173
|
-
-
|
174
|
-
-
|
247
|
+
- on.InterstitialAdLoaded
|
248
|
+
- on.InterstitialAdFailedToLoad
|
175
249
|
|
176
250
|
### Event Show
|
177
251
|
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
252
|
+
- on.InterstitialAdClicked
|
253
|
+
- on.InterstitialAdDismissedFullScreenContent
|
254
|
+
- on.InterstitialAdFailedToShowFullScreenContent
|
255
|
+
- on.InterstitialAdImpression
|
256
|
+
- on.InterstitialAdShowedFullScreenContent
|
183
257
|
|
184
258
|
|
185
259
|
|
186
260
|
|
187
|
-
## ( Rewarded
|
261
|
+
## ( Rewarded Ads )
|
188
262
|
|
189
263
|
### Event Load
|
190
264
|
|
191
|
-
-
|
192
|
-
-
|
265
|
+
- on.RewardedAdFailedToLoad
|
266
|
+
- on.RewardedAdLoaded
|
193
267
|
|
194
268
|
|
195
269
|
### Event Show
|
196
270
|
|
197
|
-
-
|
198
|
-
-
|
199
|
-
-
|
200
|
-
-
|
201
|
-
-
|
271
|
+
- on.rewardedAdClicked
|
272
|
+
- on.rewardedAdDismissedFullScreenContent
|
273
|
+
- on.rewardedAdFailedToShowFullScreenContent
|
274
|
+
- on.rewardedAdImpression
|
275
|
+
- on.rewardedAdShowedFullScreenContent
|
202
276
|
|
203
277
|
|
204
278
|
|
205
|
-
## ( Rewarded interstitial
|
279
|
+
## ( Rewarded interstitial Ads )
|
206
280
|
|
207
281
|
### Event Load
|
208
282
|
|
209
|
-
-
|
210
|
-
-
|
283
|
+
- on.RewardedInterstitialAdLoaded
|
284
|
+
- on.RewardedInterstitialAdFailedToLoad
|
211
285
|
|
212
286
|
|
213
287
|
### Event Show
|
214
288
|
|
215
|
-
-
|
216
|
-
-
|
217
|
-
-
|
218
|
-
-
|
219
|
-
-
|
289
|
+
- on.rewardedInterstitialAdClicked
|
290
|
+
- on.rewardedInterstitialAdDismissedFullScreenContent
|
291
|
+
- on.rewardedInterstitialAdFailedToShowFullScreenContent
|
292
|
+
- on.rewardedInterstitialAdImpression
|
293
|
+
- on.rewardedInterstitialAdShowedFullScreenContent
|
294
|
+
|
295
|
+
|
296
|
+
# Admob Mediation
|
297
|
+
<img src="https://user-images.githubusercontent.com/78555833/229587307-91a7e380-aa2d-4140-a62d-fa8e6a8dd153.png" width="500">
|
298
|
+
|
299
|
+
|
300
|
+
## get Mediation Adapter Name
|
301
|
+
|
302
|
+
[Example code ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/getMediationAdapterName.html) - get Mediation Adapter Name:
|
303
|
+
|
304
|
+
<img src="https://user-images.githubusercontent.com/78555833/230655800-0dbc3f12-72fb-4cf3-b4e6-801704fade28.png" width="250">
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
## Meta Audience Network
|
309
|
+
|
310
|
+
[Integrate Meta Audience Network with bidding :](https://developers.google.com/admob/android/mediation/meta)
|
311
|
+
- (Adapter default: 6.13.7.0)
|
312
|
+
### Installation
|
313
|
+
```sh
|
314
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-meta
|
315
|
+
```
|
316
|
+
|
317
|
+
- ================================
|
318
|
+
|
319
|
+
|
320
|
+
## Unity Ads
|
321
|
+
[Integrate Unity Ads with Mediation :](https://developers.google.com/admob/android/mediation/unity)
|
322
|
+
- (Adapter default: 4.6.1.0)
|
323
|
+
### Installation
|
324
|
+
```sh
|
325
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-unity
|
326
|
+
```
|
327
|
+
|
328
|
+
- ================================
|
329
|
+
|
330
|
+
|
331
|
+
## AppLovin Ads
|
332
|
+
[Integrate AppLovin with Mediation :](https://developers.google.com/admob/android/mediation/applovin)
|
333
|
+
- (Adapter default: 11.8.2.0)
|
334
|
+
### Installation
|
335
|
+
```sh
|
336
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-applovin
|
337
|
+
```
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
## Variables name or preference name
|
342
|
+
> __Warning__
|
343
|
+
> This is so that if I don't have time to update the Mediation Adapter version later, you can do it yourself as below.
|
344
|
+
|
345
|
+
- Cordova CLI Update Adapter version with Variables
|
346
|
+
```sh
|
347
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-meta --variable META_ADAPTER_VERSION="xxxxx"
|
348
|
+
```
|
349
|
+
- Update Adapter version with config.xml
|
350
|
+
```sh
|
351
|
+
<preference name="META_ADAPTER_VERSION" value="xxxxx" />
|
352
|
+
```
|
353
|
+
|
354
|
+
### Variables Name
|
355
|
+
|
356
|
+
- --variable META_ADAPTER_VERSION="xxxxx"
|
357
|
+
- --variable UNITY_ADAPTER_VERSION="xxxxx"
|
358
|
+
- --variable APPLOVIN_ADAPTER_VERSION="xxxxx"
|
359
|
+
|
360
|
+
### preference name
|
361
|
+
|
362
|
+
- META_ADAPTER_VERSION
|
363
|
+
- UNITY_ADAPTER_VERSION
|
364
|
+
- APPLOVIN_ADAPTER_VERSION
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
- ================================
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
> __Note__
|
374
|
+
> - ## Note Release
|
375
|
+
> emi-indo-cordova-plugin-admob@0.0.4
|
376
|
+
|
377
|
+
|
220
378
|
|
221
379
|
|
222
380
|
### Platform Support
|
@@ -224,5 +382,15 @@ alert("on Ad Loaded banner");
|
|
224
382
|
|
225
383
|
|
226
384
|
## 💰Sponsor this project
|
227
|
-
[](https://paypal.me/emiindo)
|
385
|
+
[](https://paypal.me/emiindo)
|
386
|
+
|
387
|
+
|
388
|
+
## Earn more money, with other ad networks.
|
389
|
+
- ### emi-indo-cordova-plugin-fan
|
390
|
+
|
391
|
+
[Facebook Audience Network:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-fan) - Ads:
|
392
|
+
|
393
|
+
- ### emi-indo-cordova-plugin-unityads
|
394
|
+
|
395
|
+
[Cordova Plugin Unity:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-unityads) - Ads:
|
228
396
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<script type="text/javascript" src="cordova.js"></script>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
|
7
|
+
<script>
|
8
|
+
|
9
|
+
|
10
|
+
/// ( Must be Admob App-id-original. )
|
11
|
+
|
12
|
+
/// The example here tries Interstitial ads.
|
13
|
+
|
14
|
+
var interstitialAdAdUnitId = "Must be the original AdUnitId"
|
15
|
+
|
16
|
+
|
17
|
+
function getMediationAdapterName() {
|
18
|
+
|
19
|
+
cordova.plugins.emiAdmobPlugin.loadInterstitialAd(interstitialAdAdUnitId, success, error);
|
20
|
+
|
21
|
+
function success(AdapterName){
|
22
|
+
|
23
|
+
alert(AdapterName)
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
function error(e){
|
28
|
+
|
29
|
+
alert(JSON.stringify(e))
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
};
|
34
|
+
|
35
|
+
|
36
|
+
document.addEventListener("deviceready", function(){
|
37
|
+
|
38
|
+
cordova.plugins.emiAdmobPlugin.initialize();
|
39
|
+
|
40
|
+
// event Sdk initialize
|
41
|
+
|
42
|
+
document.addEventListener('on.SdkInitializationComplete', () => {
|
43
|
+
|
44
|
+
alert("get Mediation Adapter Name");
|
45
|
+
|
46
|
+
getMediationAdapterName()
|
47
|
+
|
48
|
+
});
|
49
|
+
|
50
|
+
}, false);
|
51
|
+
|
52
|
+
|
53
|
+
</script>
|
54
|
+
|
55
|
+
<p> <button onclick="getMediationAdapterName();">get Mediation Adapter Name</button></p>
|
56
|
+
|
57
|
+
|
58
|
+
</body>
|
59
|
+
</html>
|
package/example/index.html
CHANGED
@@ -1,112 +1,132 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<script type="text/javascript" src="cordova.js"></script>
|
4
|
-
</head>
|
5
|
-
<body>
|
6
|
-
|
7
|
-
<script>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
var
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
var
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
});
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<script type="text/javascript" src="cordova.js"></script>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
|
7
|
+
<script>
|
8
|
+
|
9
|
+
|
10
|
+
var bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111"
|
11
|
+
var interstitialAdAdUnitId = "ca-app-pub-3940256099942544/1033173712"
|
12
|
+
var rewardedInterstitialAdUnitId = "ca-app-pub-3940256099942544/5354046379"
|
13
|
+
var rewardedAdAdUnitId = "ca-app-pub-3940256099942544/5224354917"
|
14
|
+
|
15
|
+
|
16
|
+
/// setting banner size: BANNER | LARGE_BANNER | MEDIUM_RECTANGLE | FULL_BANNER | LEADERBOARD | default: "" = BANNER
|
17
|
+
var size = "LARGE_BANNER"
|
18
|
+
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "" = bottom-left
|
19
|
+
var position = "bottom-center"
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
document.addEventListener("deviceready", function(){
|
24
|
+
|
25
|
+
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
26
|
+
// This needs to be done only once, ideally at app launch.
|
27
|
+
|
28
|
+
cordova.plugins.emiAdmobPlugin.initialize();
|
29
|
+
|
30
|
+
document.addEventListener('on.SdkInitializationComplete', () => {
|
31
|
+
|
32
|
+
alert("on Sdk Initialization Complete");
|
33
|
+
|
34
|
+
|
35
|
+
});
|
36
|
+
|
37
|
+
|
38
|
+
// BANNER EVENT
|
39
|
+
|
40
|
+
/*
|
41
|
+
on.bannerAdClicked
|
42
|
+
on.bannerAdClosed
|
43
|
+
on.bannerAdFailedToLoad
|
44
|
+
on.bannerAdImpression
|
45
|
+
on.bannerAdLoaded
|
46
|
+
on.bannerAdOpened
|
47
|
+
*/
|
48
|
+
document.addEventListener('on.bannerAdLoaded', () => {
|
49
|
+
|
50
|
+
alert("on banner Ad Loaded");
|
51
|
+
|
52
|
+
});
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
// Interstitial EVENT
|
57
|
+
|
58
|
+
/*
|
59
|
+
on.InterstitialAdLoaded
|
60
|
+
on.InterstitialAdFailedToLoad
|
61
|
+
on.InterstitialAdClicked
|
62
|
+
on.InterstitialAdDismissedFullScreenContent
|
63
|
+
on.InterstitialAdFailedToShowFullScreenContent
|
64
|
+
on.InterstitialAdImpression
|
65
|
+
on.InterstitialAdShowedFullScreenContent
|
66
|
+
*/
|
67
|
+
|
68
|
+
document.addEventListener('on.InterstitialAdLoaded', () => {
|
69
|
+
|
70
|
+
alert("on Interstitial Ad Loaded");
|
71
|
+
|
72
|
+
});
|
73
|
+
|
74
|
+
|
75
|
+
// Rewarded Interstitial EVENT
|
76
|
+
|
77
|
+
/*
|
78
|
+
on.RewardedInterstitialAdLoaded
|
79
|
+
on.RewardedInterstitialAdFailedToLoad
|
80
|
+
on.rewardedInterstitialAdClicked
|
81
|
+
on.rewardedInterstitialAdDismissedFullScreenContent
|
82
|
+
on.rewardedInterstitialAdFailedToShowFullScreenContent
|
83
|
+
on.rewardedInterstitialAdImpression
|
84
|
+
on.rewardedInterstitialAdShowedFullScreenContent
|
85
|
+
*/
|
86
|
+
|
87
|
+
document.addEventListener('on.RewardedInterstitialAdLoaded', () => {
|
88
|
+
|
89
|
+
alert("on Rewarded Interstitial Loaded");
|
90
|
+
|
91
|
+
});
|
92
|
+
|
93
|
+
|
94
|
+
// Rewarded EVENT
|
95
|
+
|
96
|
+
/*
|
97
|
+
on.RewardedAdFailedToLoad
|
98
|
+
on.RewardedAdLoaded
|
99
|
+
on.rewardedAdClicked
|
100
|
+
on.rewardedAdDismissedFullScreenContent
|
101
|
+
on.rewardedAdFailedToShowFullScreenContent
|
102
|
+
on.rewardedAdImpression
|
103
|
+
on.rewardedAdShowedFullScreenContent
|
104
|
+
*/
|
105
|
+
|
106
|
+
document.addEventListener('on.RewardedAdLoaded', () => {
|
107
|
+
|
108
|
+
alert("on Rewarded Ad Loaded");
|
109
|
+
|
110
|
+
});
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
}, false);
|
115
|
+
|
116
|
+
</script>
|
117
|
+
|
118
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showBannerAd(bannerAdUnitId, size, position);">Show Banner Ad</button></p>
|
119
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.removeBannerAd();">remove Banner Ad</button></p>
|
120
|
+
|
121
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.loadInterstitialAd(interstitialAdAdUnitId);">Load Interstitial Ad</button></p>
|
122
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showInterstitialAd();">Show Interstitial Ad</button></p>
|
123
|
+
|
124
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(rewardedInterstitialAdUnitId);">Load Rewarded Interstitial</button></p>
|
125
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd();">Show Rewarded Interstitial</button></p>
|
126
|
+
|
127
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.loadRewardedAd(rewardedAdAdUnitId);">Load Rewarded Ad</button></p>
|
128
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showRewardedAd();">Show Rewarded Ad</button></p>
|
129
|
+
|
130
|
+
|
131
|
+
</body>
|
112
132
|
</html>
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
2
2
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
-
id="emi-indo-cordova-plugin-admob" version="0.0.
|
3
|
+
id="emi-indo-cordova-plugin-admob" version="0.0.4">
|
4
4
|
|
5
5
|
<name>emiAdmobPlugin</name>
|
6
6
|
<description>Cordova Plugin Admob Android</description>
|
@@ -34,7 +34,7 @@
|
|
34
34
|
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
|
35
35
|
|
36
36
|
<preference name="APP_ID_ANDROID" default="ca-app-pub-3940256099942544~3347511713" />
|
37
|
-
<preference name="PLAY_SERVICES_VERSION" default="
|
37
|
+
<preference name="PLAY_SERVICES_VERSION" default="22.0.0" />
|
38
38
|
|
39
39
|
<framework src="com.google.android.gms:play-services-ads:$PLAY_SERVICES_VERSION" />
|
40
40
|
|
@@ -1 +1 @@
|
|
1
|
-
package emi.indo.cordova.plugin.admob;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CallbackContext;import org.json.JSONArray;import org.json.JSONException;import android.util.Log;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaWebView;import org.json.JSONObject;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.OnUserEarnedRewardListener;import com.google.android.gms.ads.initialization.InitializationStatus;import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.rewarded.RewardItem;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private RelativeLayout bannerViewLayout;private 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":cordova.getActivity().runOnUiThread(()-> MobileAds.initialize(cordova.getActivity(),initializationStatus -> cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onInitializationComplete');")));return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String InterstitialAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();InterstitialAd.load(cordova.getActivity(),InterstitialAdAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.InterstitialAd');");mInterstitialAd=interstitialAd;Log.i(TAG,"onAdLoaded");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());mInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.InterstitialAd');");}});});return true;case "showInterstitialAd":cordova.getActivity().runOnUiThread(()->{mInterstitialAd.show(cordova.getActivity());});return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String RewardedAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();RewardedAd.load(cordova.getActivity(),RewardedAdAdUnitId,adRequest,new RewardedAdLoadCallback(){@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedAd=null;Log.d(TAG,"The rewarded ad wasn't ready yet.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.RewardedAd');");}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;Log.d(TAG,"Ad was loaded.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.RewardedAd');");}});});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(rewardedAd!=null){rewardedAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String RewardedInterstitialAdUnitId=args.optString(0);RewardedInterstitialAd.load(cordova.getActivity(),RewardedInterstitialAdUnitId,new AdRequest.Builder().build(),new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(RewardedInterstitialAd ad){Log.d(TAG,"Ad was loaded.");rewardedInterstitialAd=ad;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.RewardedInterstitial');");}@Override public void onAdFailedToLoad(LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.RewardedInterstitial');");}});});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(rewardedInterstitialAd!=null){rewardedInterstitialAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{final String bannerAdUnitId=args.optString(0);final String size=args.optString(1);final String position=args.optString(2);if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);bannerViewLayout.setLayoutParams(params);((ViewGroup)Objects.requireNonNull(cWebView.getView())).addView(bannerViewLayout);}bannerView=new AdView(cordova.getActivity());if(Objects.equals(size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else{bannerView.setAdSize(AdSize.BANNER);}bannerView.setAdUnitId(bannerAdUnitId);AdRequest adRequest=new AdRequest.Builder().build();bannerView.loadAd(adRequest);RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}bannerView.setLayoutParams(bannerParams);bannerViewLayout.addView(bannerView);bannerView.setAdListener(new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.bannerAd');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClosed.bannerAd');");}@Override public void onAdFailedToLoad(LoadAdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.bannerAd');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.bannerAd');");}@Override public void onAdLoaded(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.bannerAd');");}@Override public void onAdOpened(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdOpened.bannerAd');");}});});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;ViewGroup parentView=(ViewGroup)bannerView.getParent();if(parentView!=null){parentView.removeView(bannerView);bannerView.destroy();bannerView=null;}});return true;}mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.InterstitialAd');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");mInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdDismissedFullScreenContent.InterstitialAd');");}@Override public void onAdFailedToShowFullScreenContent(AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");mInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToShowFullScreenContent.InterstitialAd');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.InterstitialAd');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdShowedFullScreenContent.InterstitialAd');");}});rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.rewardedAd');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdDismissedFullScreenContent.rewardedAd');");}@Override public void onAdFailedToShowFullScreenContent(AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToShowFullScreenContent.rewardedAd');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.rewardedAd');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdShowedFullScreenContent.rewardedAd');");}});rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.rewardedInterstitialAd');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdDismissedFullScreenContent.rewardedInterstitialAd');");}@Override public void onAdFailedToShowFullScreenContent(AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToShowFullScreenContent.rewardedInterstitialAd');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.rewardedInterstitialAd');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdShowedFullScreenContent.rewardedInterstitialAd');");}});return false;}}
|
1
|
+
package emi.indo.cordova.plugin.admob;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CallbackContext;import org.apache.cordova.PluginResult;import org.json.JSONArray;import org.json.JSONException;import android.util.Log;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaWebView;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import androidx.annotation.NonUiContext;import com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.ResponseInfo;import com.google.android.gms.ads.VersionInfo;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.initialization.InitializationStatus;import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import com.google.android.gms.common.api.Status;import java.util.Map;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private RelativeLayout bannerViewLayout;private CallbackContext rewardedCallbacks;private AdView bannerView;static boolean isbannerShow=true;static boolean isinterstitialload=false;static boolean isrewardedInterstitialload=false;static boolean isrewardedload=false;public void initialize(CordovaInterface cordova,CordovaWebView webView){super.initialize(cordova,webView);cWebView=webView;}public boolean execute(String action,JSONArray args,final CallbackContext callbackContext)throws JSONException{switch(action){case "initialize":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);assert status!=null;Log.d(TAG,String.format("Adapter name:%s,Description:%s,Latency:%d",adapterClass,status.getDescription(),status.getLatency()));}callbackContext.success(mobileAds.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.SdkInitializationComplete');");});return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String interstitialAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();InterstitialAd.load(cordova.getActivity(),interstitialAdAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){isinterstitialload=true;mInterstitialAd=interstitialAd;Log.i(TAG,"onAdLoaded");callbackContext.success(interstitialAd.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdLoaded');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());mInterstitialAd=null;isinterstitialload=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdFailedToLoad');");}});});return true;case "showInterstitialAd":if(isinterstitialload){cordova.getActivity().runOnUiThread(()->{mInterstitialAd.show(cordova.getActivity());});}else{callbackContext.error("The Interstitial ad wasn't ready yet");}return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String rewardedAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();RewardedAd.load(cordova.getActivity(),rewardedAdAdUnitId,adRequest,new RewardedAdLoadCallback(){@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedAd=null;isrewardedload=false;Log.d(TAG,"The rewarded ad wasn't ready yet.");callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdFailedToLoad');");}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;isrewardedload=true;Log.d(TAG,"Ad was loaded.");callbackContext.success(ad.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdLoaded');");}});});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedload){rewardedAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String rewardedInterstitialAdUnitId=args.optString(0);RewardedInterstitialAd.load(cordova.getActivity(),rewardedInterstitialAdUnitId,new AdRequest.Builder().build(),new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull RewardedInterstitialAd ad){Log.d(TAG,"Ad was loaded.");rewardedInterstitialAd=ad;isrewardedInterstitialload=true;callbackContext.success(ad.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdLoaded');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedInterstitialAd=null;isrewardedInterstitialload=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdFailedToLoad');");}});});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedInterstitialload){rewardedInterstitialAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{final String bannerAdUnitId=args.optString(0);final String size=args.optString(1);final String position=args.optString(2);final int adaptiveWidth=args.optInt(3);if(isbannerShow){if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);bannerViewLayout.setLayoutParams(params);((ViewGroup)Objects.requireNonNull(cWebView.getView())).addView(bannerViewLayout);}bannerView=new AdView(cordova.getActivity());if(Objects.equals(size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else if(Objects.equals(size,"Anchored_adaptive")){bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),adaptiveWidth));}else if(Objects.equals(size,"Inline_adaptive")){bannerView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(cordova.getActivity(),adaptiveWidth));}else{bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),320));}bannerView.setAdUnitId(bannerAdUnitId);AdRequest adRequest=new AdRequest.Builder().build();bannerView.loadAd(adRequest);RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}bannerView.setLayoutParams(bannerParams);bannerViewLayout.addView(bannerView);bannerView.setAdListener(new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClicked');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClosed');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError adError){callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdFailedToLoad');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdImpression');");}@Override public void onAdLoaded(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdLoaded');");}@Override public void onAdOpened(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdOpened');");}});}});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;ViewGroup parentView=(ViewGroup)bannerView.getParent();if(parentView!=null){parentView.removeView(bannerView);bannerView.destroy();bannerView=null;isbannerShow=true;}else{isbannerShow=true;}});return true;}mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");mInterstitialAd=null;isinterstitialload=false;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;}}
|
package/www/emiAdmobPlugin.js
CHANGED
@@ -5,8 +5,8 @@ exports.initialize = function (arg0, success, error) {
|
|
5
5
|
exec(success, error, 'emiAdmobPlugin', 'initialize', [arg0]);
|
6
6
|
};
|
7
7
|
|
8
|
-
exports.showBannerAd = function (bannerAdUnitId, size, position, success, error) {
|
9
|
-
exec(success, error, 'emiAdmobPlugin', 'showBannerAd', [bannerAdUnitId, size, position]);
|
8
|
+
exports.showBannerAd = function (bannerAdUnitId, size, position, adaptiveWidth, success, error) {
|
9
|
+
exec(success, error, 'emiAdmobPlugin', 'showBannerAd', [bannerAdUnitId, size, position, adaptiveWidth]);
|
10
10
|
};
|
11
11
|
|
12
12
|
exports.removeBannerAd = function (arg0, success, error) {
|