emi-indo-cordova-plugin-admob 0.0.1 → 0.0.3
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/LICENSE +3 -17
- package/README.md +185 -67
- package/example/index.html +131 -58
- package/package.json +3 -3
- package/plugin.xml +46 -42
- package/src/android/emiAdmobPlugin.java +1 -1
package/LICENSE
CHANGED
@@ -1,21 +1,7 @@
|
|
1
|
-
|
1
|
+
## ISC License
|
2
2
|
|
3
3
|
Copyright (c) 2023 EMI-INDO
|
4
4
|
|
5
|
-
Permission is hereby granted,
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
11
6
|
|
12
|
-
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
@@ -2,10 +2,14 @@
|
|
2
2
|
Cordova Plugin Admob Android
|
3
3
|
|
4
4
|
### Mobile Ads SDK (Android: 21.5.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 21.5.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 21.5.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.
|
@@ -14,66 +18,97 @@
|
|
14
18
|
> - ### No Ad-Sharing
|
15
19
|
> - ### No Remote Control
|
16
20
|
> - ### I guarantee 100% revenue for you.
|
21
|
+
> - [Code source:](https://github.com/googleads/googleads-mobile-android-examples) - Admob:
|
17
22
|
|
18
23
|
|
19
|
-
## Features
|
20
24
|
|
21
|
-
|
22
|
-
-
|
23
|
-
|
24
|
-
- Rewarded interstitial ads
|
25
|
-
- App Open Ads (Coming soon)
|
25
|
+
|
26
|
+
https://user-images.githubusercontent.com/78555833/228323239-e9e18e74-b814-4ca8-ab86-b2e28437e61c.mp4
|
27
|
+
|
26
28
|
|
27
29
|
|
28
30
|
|
31
|
+
## Features
|
32
|
+
|
33
|
+
- Banner Ads
|
34
|
+
- Interstitial Ads
|
35
|
+
- Rewarded Ads
|
36
|
+
- Rewarded interstitial Ads
|
37
|
+
|
38
|
+
## Coming soon
|
39
|
+
- App Open Ads
|
40
|
+
- User Consent
|
41
|
+
- Mediation ( In the process )
|
42
|
+
|
29
43
|
|
30
44
|
## Installation
|
31
45
|
|
32
46
|
```sh
|
33
|
-
emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713
|
47
|
+
cordova plugin add emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713
|
48
|
+
```
|
49
|
+
### Or
|
50
|
+
```sh
|
51
|
+
cordova plugin add https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713
|
52
|
+
```
|
53
|
+
## Remove
|
54
|
+
```sh
|
55
|
+
cordova plugin rm emi-indo-cordova-plugin-admob
|
34
56
|
```
|
35
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
|
+
```
|
36
63
|
|
37
|
-
## deviceready
|
38
64
|
|
39
|
-
```sh
|
40
|
-
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
41
|
-
// This needs to be done only once, ideally at app launch.
|
42
65
|
|
43
|
-
|
66
|
+
## 💰Sponsor this project
|
67
|
+
[](https://paypal.me/emiindo)
|
44
68
|
|
45
|
-
|
69
|
+
## deviceready
|
46
70
|
|
47
|
-
|
71
|
+
[Example ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/index.html) - index.html:
|
48
72
|
|
49
|
-
});
|
50
73
|
|
51
74
|
|
52
|
-
```
|
53
|
-
## Banner ads
|
54
75
|
|
55
76
|
```sh
|
56
|
-
var AdUnitId = {
|
57
77
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
78
|
+
|
79
|
+
var bannerAdUnitId = "ca-app-pub-3940256099942544/6300978111"
|
80
|
+
var interstitialAdAdUnitId = "ca-app-pub-3940256099942544/1033173712"
|
81
|
+
var rewardedInterstitialAdUnitId = "ca-app-pub-3940256099942544/5354046379"
|
82
|
+
var rewardedAdAdUnitId = "ca-app-pub-3940256099942544/5224354917"
|
62
83
|
|
63
84
|
|
64
|
-
}
|
65
85
|
|
66
|
-
|
86
|
+
|
87
|
+
/// setting banner size: BANNER | LARGE_BANNER | MEDIUM_RECTANGLE | FULL_BANNER | LEADERBOARD | default: "BANNER" | (Smart Banners = DEPRECATED)
|
67
88
|
var size = "LARGE_BANNER"
|
68
|
-
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "
|
89
|
+
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "bottom-left"
|
69
90
|
var position = "bottom-center"
|
70
91
|
|
71
92
|
|
72
|
-
//
|
73
|
-
//
|
93
|
+
// Before loading ads, have your app initialize the Google Mobile Ads SDK by calling
|
94
|
+
// This needs to be done only once, ideally at app launch.
|
95
|
+
|
96
|
+
cordova.plugins.emiAdmobPlugin.initialize();
|
97
|
+
|
98
|
+
document.addEventListener('on.SdkInitializationComplete', () => {
|
99
|
+
|
100
|
+
alert("on Sdk Initialization Complete");
|
101
|
+
|
102
|
+
});
|
103
|
+
|
74
104
|
|
75
105
|
```
|
76
106
|
|
107
|
+
## Banner Ads
|
108
|
+
```sh
|
109
|
+
// Load a Show cordova.plugins.emiAdmobPlugin.showBannerAd(bannerAdUnitId, size, position);
|
110
|
+
// remove cordova.plugins.emiAdmobPlugin.removeBannerAd();
|
111
|
+
```
|
77
112
|
[Banner ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-banner-ads-) - callback:
|
78
113
|
|
79
114
|
|
@@ -81,11 +116,11 @@ var position = "bottom-center"
|
|
81
116
|
|
82
117
|
```sh
|
83
118
|
|
84
|
-
// Load cordova.plugins.emiAdmobPlugin.loadInterstitialAd(
|
119
|
+
// Load cordova.plugins.emiAdmobPlugin.loadInterstitialAd(interstitialAdAdUnitId);
|
85
120
|
|
86
121
|
// Show cordova.plugins.emiAdmobPlugin.showInterstitialAd();
|
87
|
-
|
88
122
|
```
|
123
|
+
|
89
124
|
[Interstitial ads event](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob#-interstitial-ads-) - callback:
|
90
125
|
|
91
126
|
|
@@ -94,7 +129,7 @@ var position = "bottom-center"
|
|
94
129
|
|
95
130
|
```sh
|
96
131
|
|
97
|
-
// Load cordova.plugins.emiAdmobPlugin.loadRewardedAd(
|
132
|
+
// Load cordova.plugins.emiAdmobPlugin.loadRewardedAd(rewardedAdAdUnitId);
|
98
133
|
|
99
134
|
// Show cordova.plugins.emiAdmobPlugin.showRewardedAd();
|
100
135
|
|
@@ -107,7 +142,7 @@ var position = "bottom-center"
|
|
107
142
|
|
108
143
|
```sh
|
109
144
|
|
110
|
-
// Load cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(
|
145
|
+
// Load cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(rewardedInterstitialAdUnitId);
|
111
146
|
|
112
147
|
// Show cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd();
|
113
148
|
|
@@ -124,81 +159,164 @@ var position = "bottom-center"
|
|
124
159
|
### event code
|
125
160
|
|
126
161
|
```sh
|
127
|
-
document.addEventListener('
|
162
|
+
document.addEventListener('on.bannerAdLoaded', () => {
|
128
163
|
|
129
|
-
alert("on Ad Loaded
|
164
|
+
alert("on.banner Ad Loaded");
|
130
165
|
|
131
166
|
});
|
132
167
|
|
133
168
|
```
|
134
169
|
|
135
|
-
## (
|
170
|
+
## ( SDK )
|
171
|
+
- on.SdkInitializationComplete
|
172
|
+
|
136
173
|
|
137
|
-
|
174
|
+
## ( Banner Ads )
|
138
175
|
|
139
|
-
|
140
|
-
- onAdClosed.bannerAd
|
141
|
-
- onAdFailedToLoad.bannerAd
|
142
|
-
- onAdImpression.bannerAd
|
143
|
-
- onAdLoaded.bannerAd
|
144
|
-
- onAdOpened.bannerAd
|
176
|
+
### Event Load a Show
|
145
177
|
|
178
|
+
- on.bannerAdClicked
|
179
|
+
- on.bannerAdClosed
|
180
|
+
- on.bannerAdFailedToLoad
|
181
|
+
- on.bannerAdImpression
|
182
|
+
- on.bannerAdLoaded
|
183
|
+
- on.bannerAdOpened
|
146
184
|
|
147
185
|
|
148
186
|
|
149
|
-
|
187
|
+
|
188
|
+
## ( Interstitial Ads )
|
150
189
|
|
151
190
|
### Event Load
|
152
191
|
|
153
|
-
-
|
154
|
-
-
|
192
|
+
- on.InterstitialAdLoaded
|
193
|
+
- on.InterstitialAdFailedToLoad
|
155
194
|
|
156
195
|
### Event Show
|
157
196
|
|
158
|
-
-
|
159
|
-
-
|
160
|
-
-
|
161
|
-
-
|
162
|
-
-
|
197
|
+
- on.InterstitialAdClicked
|
198
|
+
- on.InterstitialAdDismissedFullScreenContent
|
199
|
+
- on.InterstitialAdFailedToShowFullScreenContent
|
200
|
+
- on.InterstitialAdImpression
|
201
|
+
- on.InterstitialAdShowedFullScreenContent
|
163
202
|
|
164
203
|
|
165
204
|
|
166
205
|
|
167
|
-
## ( Rewarded
|
206
|
+
## ( Rewarded Ads )
|
168
207
|
|
169
208
|
### Event Load
|
170
209
|
|
171
|
-
-
|
172
|
-
-
|
210
|
+
- on.RewardedAdFailedToLoad
|
211
|
+
- on.RewardedAdLoaded
|
173
212
|
|
174
213
|
|
175
214
|
### Event Show
|
176
215
|
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
216
|
+
- on.rewardedAdClicked
|
217
|
+
- on.rewardedAdDismissedFullScreenContent
|
218
|
+
- on.rewardedAdFailedToShowFullScreenContent
|
219
|
+
- on.rewardedAdImpression
|
220
|
+
- on.rewardedAdShowedFullScreenContent
|
182
221
|
|
183
222
|
|
184
223
|
|
185
|
-
## ( Rewarded interstitial
|
224
|
+
## ( Rewarded interstitial Ads )
|
186
225
|
|
187
226
|
### Event Load
|
188
227
|
|
189
|
-
-
|
190
|
-
-
|
228
|
+
- on.RewardedInterstitialAdLoaded
|
229
|
+
- on.RewardedInterstitialAdFailedToLoad
|
191
230
|
|
192
231
|
|
193
232
|
### Event Show
|
194
233
|
|
195
|
-
-
|
196
|
-
-
|
197
|
-
-
|
198
|
-
-
|
199
|
-
-
|
234
|
+
- on.rewardedInterstitialAdClicked
|
235
|
+
- on.rewardedInterstitialAdDismissedFullScreenContent
|
236
|
+
- on.rewardedInterstitialAdFailedToShowFullScreenContent
|
237
|
+
- on.rewardedInterstitialAdImpression
|
238
|
+
- on.rewardedInterstitialAdShowedFullScreenContent
|
239
|
+
|
240
|
+
|
241
|
+
# Admob Mediation
|
242
|
+
<img src="https://user-images.githubusercontent.com/78555833/229587307-91a7e380-aa2d-4140-a62d-fa8e6a8dd153.png" width="500">
|
243
|
+
|
244
|
+
## Meta Audience Network
|
245
|
+
|
246
|
+
[Integrate Meta Audience Network with bidding :](https://developers.google.com/admob/android/mediation/meta)
|
247
|
+
- (Adapter default: 6.13.7.0)
|
248
|
+
### Installation
|
249
|
+
```sh
|
250
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-meta
|
251
|
+
```
|
252
|
+
|
253
|
+
- ================================
|
254
|
+
|
255
|
+
|
256
|
+
## Unity Ads
|
257
|
+
[Integrate Unity Ads with Mediation :](https://developers.google.com/admob/android/mediation/unity)
|
258
|
+
- (Adapter default: 4.6.1.0)
|
259
|
+
### Installation
|
260
|
+
```sh
|
261
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-unity
|
262
|
+
```
|
263
|
+
|
264
|
+
- ================================
|
265
|
+
|
266
|
+
|
267
|
+
## AppLovin Ads
|
268
|
+
[Integrate AppLovin with Mediation :](https://developers.google.com/admob/android/mediation/applovin)
|
269
|
+
- (Adapter default: 11.8.2.0)
|
270
|
+
### Installation
|
271
|
+
```sh
|
272
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-applovin
|
273
|
+
```
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
## Variables name or preference name
|
278
|
+
> __Warning__
|
279
|
+
> This is so that if I don't have time to update the Mediation Adapter version later, you can do it yourself as below.
|
280
|
+
|
281
|
+
- Cordova CLI Update Adapter version with Variables
|
282
|
+
```sh
|
283
|
+
cordova plugin add emi-indo-cordova-plugin-mediation-meta --variable META_ADAPTER_VERSION="xxxxx"
|
284
|
+
```
|
285
|
+
- Update Adapter version with config.xml
|
286
|
+
```sh
|
287
|
+
<preference name="META_ADAPTER_VERSION" value="xxxxx" />
|
288
|
+
```
|
289
|
+
|
290
|
+
### Variables Name
|
291
|
+
|
292
|
+
- --variable META_ADAPTER_VERSION="xxxxx"
|
293
|
+
- --variable UNITY_ADAPTER_VERSION="xxxxx"
|
294
|
+
- --variable APPLOVIN_ADAPTER_VERSION="xxxxx"
|
295
|
+
|
296
|
+
### preference name
|
297
|
+
|
298
|
+
- META_ADAPTER_VERSION
|
299
|
+
- UNITY_ADAPTER_VERSION
|
300
|
+
- APPLOVIN_ADAPTER_VERSION
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
### Platform Support
|
307
|
+
- Android
|
200
308
|
|
201
309
|
|
202
310
|
## 💰Sponsor this project
|
203
|
-
[](https://paypal.me/emiindo)
|
311
|
+
[](https://paypal.me/emiindo)
|
312
|
+
|
313
|
+
|
314
|
+
## Earn more money, with other ad networks.
|
315
|
+
- ### emi-indo-cordova-plugin-fan
|
316
|
+
|
317
|
+
[Facebook Audience Network:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-fan) - Ads:
|
318
|
+
|
319
|
+
- ### emi-indo-cordova-plugin-unityads
|
320
|
+
|
321
|
+
[Cordova Plugin Unity:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-unityads) - Ads:
|
204
322
|
|
package/example/index.html
CHANGED
@@ -1,59 +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
|
-
|
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>
|
59
132
|
</html>
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "emi-indo-cordova-plugin-admob",
|
3
|
-
"version": "0.0.
|
4
|
-
"description": "",
|
3
|
+
"version": "0.0.3",
|
4
|
+
"description": "Cordova Plugin Admob Android",
|
5
5
|
"cordova": {
|
6
6
|
"id": "emi-indo-cordova-plugin-admob",
|
7
7
|
"platforms": [
|
@@ -21,7 +21,7 @@
|
|
21
21
|
|
22
22
|
],
|
23
23
|
"author": "EMI INDO",
|
24
|
-
"license": "
|
24
|
+
"license": "ISC",
|
25
25
|
"repository": {
|
26
26
|
"type": "git",
|
27
27
|
"url": "git+https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob.git"
|
package/plugin.xml
CHANGED
@@ -1,42 +1,46 @@
|
|
1
|
-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
<
|
6
|
-
</
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
<
|
17
|
-
|
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
|
-
|
1
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
2
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
id="emi-indo-cordova-plugin-admob" version="0.0.3">
|
4
|
+
|
5
|
+
<name>emiAdmobPlugin</name>
|
6
|
+
<description>Cordova Plugin Admob Android</description>
|
7
|
+
<author>EMI INDO</author>
|
8
|
+
<license>ISC</license>
|
9
|
+
|
10
|
+
<js-module src="www/emiAdmobPlugin.js" name="emiAdmobPlugin">
|
11
|
+
<clobbers target="cordova.plugins.emiAdmobPlugin"/>
|
12
|
+
</js-module>
|
13
|
+
|
14
|
+
<engines>
|
15
|
+
<engine name="cordova" version=">=7.0.0" />
|
16
|
+
<engine name="cordova-android" version=">=6.0.0" />
|
17
|
+
</engines>
|
18
|
+
|
19
|
+
|
20
|
+
<platform name="android">
|
21
|
+
<config-file parent="/*" target="res/xml/config.xml">
|
22
|
+
<feature name="emiAdmobPlugin">
|
23
|
+
<param name="android-package" value="emi.indo.cordova.plugin.admob.emiAdmobPlugin"/>
|
24
|
+
</feature>
|
25
|
+
</config-file>
|
26
|
+
|
27
|
+
|
28
|
+
<config-file target="AndroidManifest.xml" parent="/manifest/application">
|
29
|
+
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:excludeFromRecents="true" android:name="com.google.android.gms.ads.AdActivity" android:noHistory="true" />
|
30
|
+
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="$APP_ID_ANDROID" />
|
31
|
+
<meta-data android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT" android:value="true"/>
|
32
|
+
</config-file>
|
33
|
+
|
34
|
+
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
|
35
|
+
|
36
|
+
<preference name="APP_ID_ANDROID" default="ca-app-pub-3940256099942544~3347511713" />
|
37
|
+
<preference name="PLAY_SERVICES_VERSION" default="21.5.0" />
|
38
|
+
|
39
|
+
<framework src="com.google.android.gms:play-services-ads:$PLAY_SERVICES_VERSION" />
|
40
|
+
|
41
|
+
|
42
|
+
<config-file parent="/*" target="AndroidManifest.xml"/>
|
43
|
+
<source-file src="src/android/emiAdmobPlugin.java" target-dir="src/emi/indo/cordova/plugin/admob"/>
|
44
|
+
|
45
|
+
</platform>
|
46
|
+
</plugin>
|
@@ -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);});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;}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');");}});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 com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.initialization.InitializationStatus;import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import java.util.Map;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private RelativeLayout bannerViewLayout;private CallbackContext rewardedCallbacks;private AdView bannerView;static boolean isbannerShow=true;static boolean isinterstitialload=false;static boolean isrewardedInterstitialload=false;static boolean isrewardedload=false;public void initialize(CordovaInterface cordova,CordovaWebView webView){super.initialize(cordova,webView);cWebView=webView;}public boolean execute(String action,JSONArray args,final CallbackContext callbackContext)throws JSONException{switch(action){case "initialize":MobileAds.initialize(cordova.getActivity(),initializationStatus ->{Map<String,AdapterStatus> statusMap=initializationStatus.getAdapterStatusMap();for(String adapterClass:statusMap.keySet()){AdapterStatus status=statusMap.get(adapterClass);assert status!=null;callbackContext.success("Adapter name: "+adapterClass+"Description: "+status.getDescription()+"Latency: "+status.getLatency());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.SdkInitializationComplete');");});return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String interstitialAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();InterstitialAd.load(cordova.getActivity(),interstitialAdAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){isinterstitialload=true;mInterstitialAd=interstitialAd;Log.i(TAG,"onAdLoaded");callbackContext.success(interstitialAd.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdLoaded');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());mInterstitialAd=null;isinterstitialload=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdFailedToLoad');");}});});return true;case "showInterstitialAd":if(isinterstitialload){cordova.getActivity().runOnUiThread(()->{mInterstitialAd.show(cordova.getActivity());});}else{callbackContext.error("The Interstitial ad wasn't ready yet");}return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String rewardedAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();RewardedAd.load(cordova.getActivity(),rewardedAdAdUnitId,adRequest,new RewardedAdLoadCallback(){@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedAd=null;isrewardedload=false;Log.d(TAG,"The rewarded ad wasn't ready yet.");callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdFailedToLoad');");}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;isrewardedload=true;Log.d(TAG,"Ad was loaded.");callbackContext.success(ad.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedAdLoaded');");}});});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedload){rewardedAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String rewardedInterstitialAdUnitId=args.optString(0);RewardedInterstitialAd.load(cordova.getActivity(),rewardedInterstitialAdUnitId,new AdRequest.Builder().build(),new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull RewardedInterstitialAd ad){Log.d(TAG,"Ad was loaded.");rewardedInterstitialAd=ad;isrewardedInterstitialload=true;callbackContext.success(ad.getResponseInfo().getMediationAdapterClassName());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdLoaded');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedInterstitialAd=null;isrewardedInterstitialload=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.RewardedInterstitialAdFailedToLoad');");}});});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedInterstitialload){rewardedInterstitialAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{final String bannerAdUnitId=args.optString(0);final String size=args.optString(1);final String position=args.optString(2);if(isbannerShow){if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);bannerViewLayout.setLayoutParams(params);((ViewGroup)Objects.requireNonNull(cWebView.getView())).addView(bannerViewLayout);}bannerView=new AdView(cordova.getActivity());if(Objects.equals(size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else{bannerView.setAdSize(AdSize.BANNER);}bannerView.setAdUnitId(bannerAdUnitId);AdRequest adRequest=new AdRequest.Builder().build();bannerView.loadAd(adRequest);RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}bannerView.setLayoutParams(bannerParams);bannerViewLayout.addView(bannerView);bannerView.setAdListener(new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClicked');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdClosed');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError adError){callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdFailedToLoad');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdImpression');");}@Override public void onAdLoaded(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdLoaded');");}@Override public void onAdOpened(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAdOpened');");}});}});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;ViewGroup parentView=(ViewGroup)bannerView.getParent();if(parentView!=null){parentView.removeView(bannerView);bannerView.destroy();bannerView=null;isbannerShow=true;}else{isbannerShow=true;}});return true;}mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.InterstitialAdShowedFullScreenContent');");}});rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAdShowedFullScreenContent');");}});rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdClicked');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdDismissedFullScreenContent');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdFailedToShowFullScreenContent');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdImpression');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInterstitialAdShowedFullScreenContent');");}});return false;}}
|