cordova-plugin-admob-nextgen 1.3.9 → 1.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,9 @@
11
11
 
12
12
  **The Ultimate AdMob Monetization Solution for Cordova/Capacitor/Framework7.**
13
13
 
14
- This plugin is a complete **rewrite and re-architecture** of the classic AdMob integration, built specifically for the **[Google Mobile Ads Next Generation SDK](https://ads-developers.googleblog.com/2026/01/announcing-google-mobile-ads-next-gen.html)**. It moves away from legacy implementations to modern `SurfaceControl`, optimized layouts, and background threading, ensuring maximum performance, stability, and revenue.
14
+ This plugin is a complete **rewrite and re-architecture** of the classic AdMob integration, built specifically for the **[Google Mobile Ads Next Generation SDK](https://ads-developers.googleblog.com/2026/01/announcing-google-mobile-ads-next-gen.html)**.
15
+
16
+ It moves away from legacy implementations to modern `SurfaceControl`, optimized layouts, and background threading, ensuring maximum performance, stability, and revenue.
15
17
 
16
18
  > **Maintained by the original creator of [EMI-INDO/emi-indo-cordova-plugin-admob](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob).** This is not just an update; it is a brand new engine designed for 2026 and beyond.
17
19
 
@@ -19,64 +21,105 @@ This plugin is a complete **rewrite and re-architecture** of the classic AdMob i
19
21
 
20
22
  ## 🚀 Why Next-Gen?
21
23
 
22
- Google has introduced a fundamental shift in how ads are rendered on Android. This plugin aligns perfectly with those changes to solve the most critical issues developers face today:
24
+ Google has introduced a fundamental shift in how ads are rendered on Android.
23
25
 
24
- 1. **Lifecycle Stability:** Solves the notorious issue where Full-Screen Ads (Interstitial, Rewarded, App Open) would crash or disappear when the app goes to the background and returns to the foreground.
25
- 2. **Android 15+ Compatibility:** Includes a built-in workaround for the [Android 15 Edge-to-Edge enforcement](https://groups.google.com/g/google-admob-ads-sdk/c/WyGsRV--EoE). It ensures the "Close/X" buttons on full-screen ads are never hidden behind the system navigation bar (API Level 35 fix).
26
- 3. **Clean Architecture:** Written from scratch using the official [Next Gen SDK Examples](https://github.com/googleads/gma-next-gen-sdk-android-examples), ensuring long-term compliance with Google Policies.
26
+ This plugin aligns perfectly with those changes to solve the most critical issues developers face today:
27
+
28
+ 1. **ANR Error Elimination:**
29
+ The legacy SDK is notorious for causing ANR (Application Not Responding) errors in the Google Play Console. This Next-Gen architecture fully resolves these threading bottlenecks.
30
+ *(See [Google's Next-Gen Announcement](https://ads-developers.googleblog.com/2026/01/announcing-google-mobile-ads-next-gen.html))*
31
+
32
+ 2. **Lifecycle Stability:**
33
+ Solves the notorious issue where Full-Screen Ads (Interstitial, Rewarded, App Open) would crash or disappear when the app goes to the background and returns to the foreground.
34
+
35
+ 3. **Smart Runtime Engine (Android 15 Edge-to-Edge):**
36
+ Intelligently detects and handles Android 14 (API 35) vs Android 15 (API 36) edge-to-edge conditions at runtime.
37
+ * Automatically secures the "Close/X" buttons on full-screen ads.
38
+ * When using the banner parameter `isOverlapping: false`, it intelligently calculates the system safe bottom insets to push the WebView content up perfectly.
39
+ * Ensures neither the ad nor your app UI is hidden behind the system navigation bar.
40
+ * Requires **zero** manual configuration from the user.
41
+ *(See [Release v1.3.9-beta.1](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/releases/tag/v1.3.9-beta.1))*
42
+
43
+ 4. **Cordova & Capacitor Agnostic:**
44
+ Intelligently identifies whether the runtime environment is Cordova or Capacitor (including deep native Java logic adjustments) to provide seamless compatibility.
45
+
46
+ 5. **Clean Architecture:**
47
+ Written from scratch using the official [Next Gen SDK Examples](https://github.com/googleads/gma-next-gen-sdk-android-examples), ensuring long-term compliance with Google Policies.
27
48
 
28
- ---
29
49
 
30
50
  ## 💰 Mission: Revenue Maximization
31
51
 
32
- This plugin is designed with one goal: **increasing your eCPM and fill rates**. We have implemented advanced formats and technologies that are proven to outperform standard implementations.
52
+ This plugin is designed with one goal:
53
+
54
+ **increasing your eCPM and fill rates**.
55
+
56
+ It incorporates advanced formats and technologies that are proven to outperform standard implementations.
33
57
 
34
58
  ### 1. True Next-Gen Speed: Ad Preloading API ⚡
35
- This is the **real** Next-Gen feature. We have implemented the specific Preload API methods: `startBannerPreload` and `showPreloadedBanner`.
59
+ This is the **real** Next-Gen feature, this plugin implements the specific Preload API methods: `startBannerPreload` and `showPreloadedBanner`.
36
60
  * **Zero Latency:** Instead of loading an ad when you need it, the plugin maintains a "pool" of ready-to-show ads in the background.
37
61
  * **Instant Show:** When you call `showPreloadedBanner`, the ad appears instantly (0ms delay) from the pool.
38
62
 
39
63
  ### 2. Collapsible Banners (The Revenue Booster)
40
- Standard banners are often ignored by users. This plugin supports **Collapsible Banners** natively.
41
- * **Impact:** Typically delivers **3-5% higher revenue** than standard banners.
64
+ Standard banners are often ignored by users.
65
+
66
+ This plugin supports **Collapsible Banners** natively.
67
+ * **Impact:** Typically delivers **3-5% higher revenue** than standard or large adaptive banners.
42
68
  * **Mechanism:** Shows a larger ad initially (anchored top/bottom) that can be collapsed by the user, drastically increasing visibility and click-through rates (CTR).
43
69
 
44
70
  ### 3. Native Advanced Overlay (The Banner Killer)
45
- Move beyond simple 320x50 banners. The Native Overlay feature allows you to render high-performance Native Ads that look like system notifications.
71
+ Move beyond simple 320x50 banners.
72
+
73
+ The Native Overlay feature allows you to render high-performance Native Ads that look like system notifications.
46
74
  * **Impact:** Can yield **5-10% higher revenue** compared to standard banners due to higher advertiser demand for Native assets.
47
75
  * **Smart Templates:**
48
76
  * `banner_bottom`: A sleek, notification-style ad docked at the bottom.
49
77
  * `banner_top`: Docked at the top.
50
78
  * `modal_center`: A popup-style native ad.
51
- * **Policy Safe:** Includes an `isOverlapping` parameter. You can choose to overlay the ad (float) or push the webview content (safe layout), preventing accidental clicks.
52
-
53
- ---
79
+ * **Policy Safe:** Includes an `isOverlapping` parameter.
80
+ * You can choose to overlay the ad (float) or push the webview content (safe layout), preventing accidental clicks.
54
81
 
55
82
 
56
83
  ## 🛡️ Safety & Reliability
57
84
 
58
- We prioritize the safety of your AdMob account and the stability of your app.
85
+ This plugin prioritizes the safety of your AdMob account and the stability of your app.
59
86
 
60
- * **Smart Throttling (`retryInterval`)**: Prevents accidental spamming of ad requests using a global interval validation.
87
+ * **Smart Throttling (`retryInterval`)**: Solves the dreaded "high requests, low impressions" (Invalid Traffic / IVT) issue.
61
88
 
62
- - If the loadAd or showAd function is called repeatedly accidentally by JavaScript (for example because it is tied to a scroll event or application loop), the system will continuously call loadAd or showAd.
63
- ### This will cause two fatal problems:
64
- 1. Banner Ad Flickering: Ads are constantly being destroyed and redrawn.
65
- 2. Account Ban: Aggressively pulling ads (spamming impressions) is a serious violation of AdMob's Invalid Traffic (IVT) policy.
89
+ * This parameter acts as a strict anti-spam safeguard.
90
+ * If an ad load is accidentally triggered repeatedly by an app logic error (e.g., game loop, tick, or scroll event) before the ad surfaces and is viewed by the user, the `retryInterval` automatically blocks the redundant requests.
91
+
92
+ **Without this safeguard, you face two fatal problems:**
93
+ 1. **Banner Ad Flickering:** Ads are constantly being destroyed and redrawn before becoming visible.
94
+ 2. **Account Ban:** Aggressively pulling ads (spamming requests without impressions) is a serious violation of AdMob's Invalid Traffic policy.
66
95
 
67
96
  * **Background Thread Loading**: All ad requests are dispatched on background threads, ensuring your app's UI never freezes.
68
97
 
98
+
69
99
  ---
70
100
 
71
101
 
72
- ## Cordova/Capacitor/Framework7 AdMob Next-Gen: Installation & Usage Guide
102
+ ## Cordova/Capacitor/Framework7 AdMob Next-Gen:
103
+
104
+ ### Installation & Usage Guide
73
105
 
74
106
  ---
75
107
  > Fastest test (APK Debug): **[⚡ With github action ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/discussions/4)** (Optional)
76
108
  ---
77
109
 
110
+ ### 📦 Current SDK Versions (Maintained & Up-to-Date)
111
+
112
+ This plugin is regularly updated to support the latest standards.
113
+
114
+ | Component | Platform | Version | Release Notes |
115
+ | :--- | :--- | :--- | :--- |
116
+ | **GMA Next-Gen SDK** | Android | **1.1.0** | [View Notes](https://developers.google.com/admob/android/next-gen/rel-notes) |
117
+ | **UMP SDK** | Android | **4.0.0** | [View Notes](https://developers.google.com/admob/android/privacy/release-notes) |
118
+ | **Mobile Ads SDK** | iOS | **13.3.0** | [View Notes](https://developers.google.com/admob/ios/rel-notes) |
119
+ | **UMP SDK** | iOS | **3.1.0** | [View Notes](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/privacy/download) |
120
+
78
121
  ### 🎉 View all plugin release notes
79
- - 👉 [**Releases**](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/releases)
122
+ - 👉 [**Releases notes**](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/releases)
80
123
 
81
124
  ---
82
125
 
@@ -84,14 +127,14 @@ We prioritize the safety of your AdMob account and the stability of your app.
84
127
  ## 1. Cordova or Framework7
85
128
 
86
129
  ### Option A: Via CLI
87
- Install the plugin directly using the Cordova CLI. You must provide your AdMob App ID.
130
+ Install the plugin directly using the Cordova CLI, You must provide your AdMob App ID.
88
131
 
89
132
  cordova plugin add cordova-plugin-admob-nextgen --save --variable APP_ID_ANDROID="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" --variable APP_ID_IOS="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"
90
133
 
91
134
  ### Option B: Via config.xml
92
135
  Add this to your `config.xml` to restore the plugin automatically.
93
136
 
94
- <plugin name="cordova-plugin-admob-nextgen" spec="latest">
137
+ <plugin name="cordova-plugin-admob-nextgen">
95
138
  <variable name="APP_ID_ANDROID" value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" />
96
139
  <variable name="APP_ID_IOS" value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" />
97
140
  </plugin>
@@ -318,57 +361,6 @@ High-performance native templates.
318
361
 
319
362
  ---
320
363
 
321
- ## 5. Ad Preloading (Banner) - Android Only
322
-
323
- Use the background engine to pool ads for 0ms latency.
324
-
325
- ### Usage
326
-
327
- // 1. Start Engine
328
- admobNextGen.startBannerPreload({
329
- adUnitId: 'ca-app-pub-xxx/xxx',
330
- size: 'ADAPTIVE', // 'BANNER', 'LARGE_BANNER', 'MEDIUM_RECTANGLE', 'ADAPTIVE', 'FULL_BANNER', 'LEADERBOARD'
331
- position: 'bottom', // 'top' or 'bottom'
332
- collapsible: false, // true = Enable Collapsible Format (High Revenue)
333
- isOverlapping: false,
334
- retryInterval: 5000 // Anti-spam delay (ms)
335
- });
336
-
337
- // 2. Show Instantly (from pool)
338
- admobNextGen.showPreloadedBanner();
339
-
340
- // 3. Stop/Remove Engine
341
- admobNextGen.stopBannerPreload();
342
-
343
- // 4. Hide Engine
344
- admobNextGen.hideBannerPreload()
345
-
346
-
347
- ### Banner Events
348
-
349
- document.addEventListener('on.banner.load', (data) => {
350
- console.log("Banner Loaded: " + data.width + "x" + data.height);
351
- console.log("Collapsible: " + data.isCollapsible);
352
- });
353
- document.addEventListener('on.preload.failed', (err) => console.error(err));
354
- document.addEventListener('on.banner.revenue', (data) => {
355
- console.log("Revenue: " + data.value + " " + data.currency);
356
- });
357
- document.addEventListener('on.banner.clicked', () => console.log("Clicked"));
358
- document.addEventListener('on.banner.impression', () => console.log("Impression"));
359
-
360
- // else
361
- on.preload.available
362
- on.preload.failed
363
- on.preload.exhausted
364
- on.banner.opened
365
- on.banner.closed
366
- on.banner.failed.show
367
- on.banner.refreshed
368
- on.banner.refresh.failed
369
-
370
- ---
371
-
372
364
  ## 6. App Open Ads
373
365
 
374
366
  Supports Auto-Resume logic.
@@ -385,9 +377,6 @@ Supports Auto-Resume logic.
385
377
 
386
378
  admobNextGen.showAppOpenAd();
387
379
 
388
- ### With App Open Ad Preload
389
- > App Open Ad Preload **[⚡ Modern ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/tree/main/simple-example/www/js/AppOpenAdPreload.js)**
390
-
391
380
  ### App Open Events
392
381
 
393
382
  document.addEventListener('on.appopen.revenue', (data) => console.log(data));
@@ -504,12 +493,89 @@ Auto-showing rewarded format (no opt-in).
504
493
 
505
494
  ---
506
495
 
496
+
497
+ ## 10. Preloader Engine (Android Only - Next-Gen SDK)
498
+
499
+ The AdMob Next-Gen SDK introduces a powerful background Preloader Engine that caches ads in a buffer pool, enabling zero-latency ad rendering.
500
+
501
+ > **⚠️ IMPORTANT WARNING & BEST PRACTICES:**
502
+ > * **Android Only:** The Preloader engine is currently an exclusive feature of the Android Next-Gen SDK.
503
+ > * **Strict Method Separation:** NEVER mix Classic methods with Preloader methods to avoid logic conflicts.
504
+ > * If you use `createBanner`, you MUST use `showBanner`.
505
+ > * If you use `startBannerPreload`, you MUST use `showPreloadedBanner`.
506
+ > * **Cross-Platform (iOS) Consideration:** Events are unified. A `source` flag (`data.source === "preloader"`) is injected into the event data on Android. However, it is highly recommended to maintain a single unified logic flow. Relying strictly on the `source === "preloader"` condition will cause issues on iOS, as iOS relies entirely on the Classic implementation.
507
+
508
+ ### Method Mapping (Classic vs Preloader)
509
+
510
+ | Ad Format | Start Preload | Show Polled Ad | Other Preload Methods |
511
+ | :--- | :--- | :--- | :--- |
512
+ | **Banner** | `startBannerPreload(obj)` | `showPreloadedBanner()` | `stopBannerPreload()`, `hideBannerPreload()` |
513
+ | **App Open** | `startAppOpenPreload(obj)` | `showPreloadedAppOpenAd()` | `isAppOpenAdAvailable()` |
514
+ | **Interstitial** | `startInterstitialPreload(obj)` | `showPreloadedInterstitial()` | `stopInterstitialPreload()`, `isInterstitialAdAvailable()` |
515
+ | **Rewarded** | `startRewardedPreload(obj)` | `showPreloadedRewarded()` | `stopRewardedPreload()`, `isRewardedAdAvailable()` |
516
+ | **Rewarded Interstitial** | `startRewardedInterstitialPreload(obj)` | `showPreloadedRewardedInterstitial()` | `stopRewardedInterstitialPreload()`, `isRewardedInterstitialAdAvailable()` |
517
+
518
+ ### Implementation Example
519
+
520
+ - [⚡ Example preloading ](https://github.com/swaplab-engine/cordova-plugin-admob-nextgen/tree/main/simple-example/www/js/preloading)
521
+
522
+ **1. Start the Preloader**
523
+ Run this once (e.g., after SDK initialization). The engine will automatically maintain the buffer in the background.
524
+
525
+ ```javascript
526
+ admobNextGen.startRewardedPreload({
527
+ adUnitId: 'ca-app-pub-xxx/xxx',
528
+ bufferSize: 2, // (Optional) Number of ads to cache. Default: 1 max 3
529
+ isAutoShow: false, // (Optional) Show immediately when the first ad is ready
530
+ retryInterval: 5000 // (Optional) Anti-spam protection in ms
531
+ });
532
+ ```
533
+
534
+ **2. Show the Preloaded Ad**
535
+ Call this when the user interacts with your app. It will render instantly from the local buffer.
536
+
537
+ ```javascript
538
+ admobNextGen.showPreloadedRewarded();
539
+ ```
540
+
541
+ ### Unified Events & Preloader Exclusives
542
+
543
+ To streamline development, the Preloader triggers the **exact same lifecycle events** as the Classic mode (e.g., `on.rewarded.loaded`, `on.rewarded.dismissed`). You only need to write one event listener for both modes.
544
+
545
+ **Preloader Exclusive Event:**
546
+ The only event strictly unique to the Preloader is the `exhausted` event. This fires when the buffer pool is completely empty and the SDK stops trying to fetch new ads.
547
+
548
+ ```javascript
549
+ // Example: Unique Preloader Event
550
+ document.addEventListener('on.rewarded.exhausted', () => {
551
+ console.warn("Background ad buffer is empty!");
552
+ });
553
+ ```
554
+
555
+ **Optional: Checking the Event Source**
556
+ If you need to execute specific conditional logic for the preloader, you can check `data.source`. *(Remember: This flag is Android-only).*
557
+
558
+ ```javascript
559
+ document.addEventListener('on.rewarded.loaded', (e) => {
560
+ let data = e.data || e;
561
+
562
+ if (data && data.source === "preloader") {
563
+ console.log("Ad loaded via Android Preloader Engine");
564
+ } else {
565
+ console.log("Ad loaded via Classic Engine (or iOS)");
566
+ }
567
+ });
568
+ ```
569
+
570
+ ---
571
+
572
+
507
573
  ## ⚖️ Revenue Policy
508
574
 
509
575
  **No Ad-Sharing. No Hidden Fees.**
510
576
 
511
577
  Unlike many other free plugins, this project is clean:
512
- * **0% Revenue Share:** We do not inject our own Ad Unit IDs into your traffic.
578
+ * **0% Revenue Share:** This plugin do not inject our own Ad Unit IDs into your traffic.
513
579
  * **100% Control:** Every impression and click goes directly to your AdMob account.
514
580
  * **Transparent Source:** The code is open source. You can verify that no third-party SDKs or hidden backdoors exist.
515
581
 
@@ -517,7 +583,8 @@ Unlike many other free plugins, this project is clean:
517
583
 
518
584
  ## ❤️ Support the Project
519
585
 
520
- This plugin is developed and maintained in my free time. If it saved you hours of work, consider supporting the development!
586
+ This plugin is developed and maintained in my free time.
587
+ If it saved you hours of work, consider supporting the development!
521
588
 
522
589
  <a href="https://www.buymeacoffee.com/emi.indo" target="_blank">
523
590
  <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-admob-nextgen",
3
- "version": "1.3.9",
3
+ "version": "1.5.9",
4
4
  "description": "Google Mobile Ads Next Gen SDK for Cordova. High performance and modular architecture. ",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-admob-nextgen",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
2
  <plugin id="cordova-plugin-admob-nextgen"
3
- version="1.3.9"
3
+ version="1.5.9"
4
4
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
5
5
  xmlns:android="http://schemas.android.com/apk/res/android">
6
6
 
@@ -28,15 +28,15 @@
28
28
  <uses-permission android:name="android.permission.INTERNET" />
29
29
  </config-file>
30
30
 
31
+ <!-- hooks: Prevent conflicts with legacy SDKs when using mediation -->
31
32
  <framework src="src/android/hooks/admob-nextgen.gradle" custom="true" type="gradleReference" />
32
33
 
33
34
  <framework src="com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:$NEXT_GEN_SDK_VERSION" />
34
35
  <framework src="com.google.android.ump:user-messaging-platform:$UMP_VERSION" />
35
36
 
37
+ <!-- Android | IOS -->
36
38
  <source-file src="src/android/AdMobNextGen.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
37
39
  <source-file src="src/android/BannerExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
38
- <source-file src="src/android/BannerPreloadExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
39
- <source-file src="src/android/AppOpenAdPreloadExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
40
40
  <source-file src="src/android/NativeExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
41
41
  <source-file src="src/android/AppOpenAdExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
42
42
  <source-file src="src/android/InterstitialExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
@@ -44,11 +44,18 @@
44
44
  <source-file src="src/android/RewardedInterstitialExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
45
45
  <source-file src="src/android/ConsentExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
46
46
  <source-file src="src/android/GlobalSettingsExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen" />
47
+ <!-- Only Android -->
48
+ <source-file src="src/android/preloading/AppOpenAdPreloadExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen/preloading" />
49
+ <source-file src="src/android/preloading/BannerPreloadExecutor.java" target-dir="app/src/main/java/com/emi/cordova/admob/nextgen/preloading" />
50
+ <source-file src="src/android/preloading/InterstitialPreloadExecutor.java" target-dir="src/com/emi/cordova/admob/nextgen/preloading" />
51
+ <source-file src="src/android/preloading/RewardedPreloadExecutor.java" target-dir="src/com/emi/cordova/admob/nextgen/preloading" />
52
+ <source-file src="src/android/preloading/RewardedInterstitialPreloadExecutor.java" target-dir="src/com/emi/cordova/admob/nextgen/preloading" />
47
53
 
48
54
  </platform>
49
55
 
50
- <preference name="NEXT_GEN_SDK_VERSION" default="1.0.1" />
56
+ <preference name="NEXT_GEN_SDK_VERSION" default="1.1.0" />
51
57
  <preference name="UMP_VERSION" default="4.0.0" />
58
+ <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
52
59
  <preference name="APP_ID_ANDROID" default="ca-app-pub-3940256099942544~3347511713" />
53
60
 
54
61
  <platform name="ios">
@@ -152,7 +159,7 @@
152
159
  <header-file src="src/ios/RewardedInterstitialExecutor.h" />
153
160
  <source-file src="src/ios/RewardedInterstitialExecutor.m" />
154
161
  </platform>
155
-
162
+ <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~1458002511 -->
156
163
  <preference name="APP_ID_IOS" default="ca-app-pub-3940256099942544~1458002511" />
157
164
 
158
165
  </plugin>
@@ -1,5 +1,11 @@
1
1
  package com.emi.cordova.admob.nextgen;
2
2
 
3
+ import com.emi.cordova.admob.nextgen.preloading.AppOpenAdPreloadExecutor;
4
+ import com.emi.cordova.admob.nextgen.preloading.BannerPreloadExecutor;
5
+ import com.emi.cordova.admob.nextgen.preloading.InterstitialPreloadExecutor;
6
+ import com.emi.cordova.admob.nextgen.preloading.RewardedPreloadExecutor;
7
+ import com.emi.cordova.admob.nextgen.preloading.RewardedInterstitialPreloadExecutor;
8
+
3
9
  import android.app.Activity;
4
10
  import android.app.Application;
5
11
  import android.content.Context;
@@ -40,8 +46,12 @@ public class AdMobNextGen extends CordovaPlugin {
40
46
 
41
47
  private BannerPreloadExecutor bannerPreloadExecutor;
42
48
  private AppOpenAdPreloadExecutor appOpenAdPreloadExecutor;
49
+ private InterstitialPreloadExecutor interstitialPreloadExecutor;
50
+ private RewardedPreloadExecutor rewardedPreloadExecutor;
51
+ private RewardedInterstitialPreloadExecutor rewardedInterstitialPreloadExecutor;
43
52
 
44
53
  private boolean isNativeValidatorDisabled = true;
54
+ public static boolean isInitialized = false;
45
55
 
46
56
  @Override
47
57
  public void pluginInitialize() {
@@ -49,19 +59,24 @@ public class AdMobNextGen extends CordovaPlugin {
49
59
 
50
60
  applyAdMobAPI35WorkaroundIfNeeded(cordova.getActivity().getApplication());
51
61
 
62
+ globalSettingsExecutor = new GlobalSettingsExecutor(cordova);
63
+ consentExecutor = new ConsentExecutor(cordova, webView);
64
+ appOpenAdExecutor = AppOpenAdExecutor.getInstance();
65
+ appOpenAdExecutor.initialize(cordova, webView);
66
+
52
67
  bannerExecutor = new BannerExecutor(cordova, webView);
53
68
  interstitialExecutor = new InterstitialExecutor(cordova, webView);
54
69
  rewardedExecutor = new RewardedExecutor(cordova, webView);
55
70
  rewardedInterstitialExecutor = new RewardedInterstitialExecutor(cordova, webView);
56
- consentExecutor = new ConsentExecutor(cordova, webView);
57
- globalSettingsExecutor = new GlobalSettingsExecutor(cordova);
58
71
 
59
- appOpenAdExecutor = AppOpenAdExecutor.getInstance();
60
- appOpenAdExecutor.initialize(cordova, webView);
61
72
  nativeExecutor = new NativeExecutor(cordova, webView);
62
73
 
63
- bannerPreloadExecutor = new BannerPreloadExecutor(cordova, webView);
64
74
  appOpenAdPreloadExecutor = new AppOpenAdPreloadExecutor(cordova, webView);
75
+ bannerPreloadExecutor = new BannerPreloadExecutor(cordova, webView);
76
+ interstitialPreloadExecutor = new InterstitialPreloadExecutor(cordova, webView);
77
+ rewardedPreloadExecutor = new RewardedPreloadExecutor(cordova, webView);
78
+ rewardedInterstitialPreloadExecutor = new RewardedInterstitialPreloadExecutor(cordova, webView);
79
+
65
80
  }
66
81
 
67
82
  @Override
@@ -81,7 +96,9 @@ public class AdMobNextGen extends CordovaPlugin {
81
96
  }
82
97
 
83
98
  if ("requestConsentInfo".equals(action)) {
84
- consentExecutor.requestConsentInfo(args, callbackContext);
99
+ cordova.getThreadPool().execute(() -> {
100
+ consentExecutor.requestConsentInfo(args, callbackContext);
101
+ });
85
102
  return true;
86
103
  }
87
104
  if ("showPrivacyOptionsForm".equals(action)) {
@@ -98,7 +115,9 @@ public class AdMobNextGen extends CordovaPlugin {
98
115
  }
99
116
 
100
117
  if ("initialize".equals(action)) {
101
- this.initializeSDK(args, callbackContext);
118
+ cordova.getThreadPool().execute(() -> {
119
+ this.initializeSDK(args, callbackContext);
120
+ });
102
121
  return true;
103
122
  }
104
123
 
@@ -115,44 +134,12 @@ public class AdMobNextGen extends CordovaPlugin {
115
134
  return true;
116
135
  }
117
136
 
118
- if ("startBannerPreload".equals(action)) {
119
- bannerPreloadExecutor.startPreload(args, callbackContext);
120
- return true;
121
- }
122
- if ("showPreloadedBanner".equals(action)) {
123
- bannerPreloadExecutor.showPolledAd(args, callbackContext);
124
- return true;
125
- }
126
- if ("stopBannerPreload".equals(action)) {
127
- bannerPreloadExecutor.stopPreloadAndClear();
128
- callbackContext.success();
129
- return true;
130
- }
131
-
132
- if ("hideBannerPreload".equals(action)) {
133
- bannerPreloadExecutor.hideBanner(callbackContext);
134
- return true;
135
- }
136
-
137
137
  if ("removeBanner".equals(action)) {
138
138
  bannerExecutor.destroy();
139
139
  callbackContext.success();
140
140
  return true;
141
141
  }
142
142
 
143
- if ("startAppOpenPreload".equals(action)) {
144
- appOpenAdPreloadExecutor.startPreload(args, callbackContext);
145
- return true;
146
- }
147
- if ("showPreloadedAppOpenAd".equals(action)) {
148
- appOpenAdPreloadExecutor.showPolledAd(args, callbackContext);
149
- return true;
150
- }
151
- if ("isAppOpenAdAvailable".equals(action)) {
152
- appOpenAdPreloadExecutor.checkAdAvailable(args, callbackContext);
153
- return true;
154
- }
155
-
156
143
  if ("loadAppOpenAd".equals(action)) {
157
144
  if (appOpenAdExecutor != null) {
158
145
  appOpenAdExecutor.loadAd(args, callbackContext);
@@ -181,6 +168,7 @@ public class AdMobNextGen extends CordovaPlugin {
181
168
  nativeExecutor.createNativeAd(args, callbackContext);
182
169
  return true;
183
170
  }
171
+
184
172
  if ("removeNativeAd".equals(action)) {
185
173
  nativeExecutor.removeNativeAd();
186
174
  callbackContext.success();
@@ -189,6 +177,7 @@ public class AdMobNextGen extends CordovaPlugin {
189
177
 
190
178
  if ("createInterstitial".equals(action)) {
191
179
  interstitialExecutor.createInterstitial(args, callbackContext);
180
+ callbackContext.success();
192
181
  return true;
193
182
  }
194
183
  if ("showInterstitial".equals(action)) {
@@ -200,6 +189,7 @@ public class AdMobNextGen extends CordovaPlugin {
200
189
  rewardedExecutor.createRewarded(args, callbackContext);
201
190
  return true;
202
191
  }
192
+
203
193
  if ("showRewarded".equals(action)) {
204
194
  rewardedExecutor.showRewarded(callbackContext);
205
195
  return true;
@@ -209,11 +199,101 @@ public class AdMobNextGen extends CordovaPlugin {
209
199
  rewardedInterstitialExecutor.createRewardedInterstitial(args, callbackContext);
210
200
  return true;
211
201
  }
202
+
212
203
  if ("showRewardedInterstitial".equals(action)) {
213
204
  rewardedInterstitialExecutor.showRewardedInterstitial(callbackContext);
214
205
  return true;
215
206
  }
216
207
 
208
+ if ("startAppOpenPreload".equals(action)) {
209
+ appOpenAdPreloadExecutor.startPreload(args, callbackContext);
210
+ return true;
211
+ }
212
+ if ("showPreloadedAppOpenAd".equals(action)) {
213
+ appOpenAdPreloadExecutor.showPolledAd(args, callbackContext);
214
+ return true;
215
+ }
216
+ if ("isAppOpenAdAvailable".equals(action)) {
217
+ appOpenAdPreloadExecutor.checkAdAvailable(args, callbackContext);
218
+ return true;
219
+ }
220
+
221
+ if ("startBannerPreload".equals(action)) {
222
+ bannerPreloadExecutor.startPreload(args, callbackContext);
223
+ return true;
224
+ }
225
+ if ("showPreloadedBanner".equals(action)) {
226
+ bannerPreloadExecutor.showPolledAd(args, callbackContext);
227
+ return true;
228
+ }
229
+ if ("stopBannerPreload".equals(action)) {
230
+ bannerPreloadExecutor.stopPreloadAndClear();
231
+ callbackContext.success();
232
+ return true;
233
+ }
234
+
235
+ if ("hideBannerPreload".equals(action)) {
236
+ bannerPreloadExecutor.hideBanner(callbackContext);
237
+ return true;
238
+ }
239
+
240
+ if ("startInterstitialPreload".equals(action)) {
241
+ interstitialPreloadExecutor.startPreload(args, callbackContext);
242
+ return true;
243
+ }
244
+ if ("showPreloadedInterstitial".equals(action)) {
245
+ interstitialPreloadExecutor.showPolledAd(args, callbackContext);
246
+ return true;
247
+ }
248
+ if ("isInterstitialAdAvailable".equals(action)) {
249
+ interstitialPreloadExecutor.checkAdAvailable(args, callbackContext);
250
+ return true;
251
+ }
252
+ if ("stopInterstitialPreload".equals(action)) {
253
+ interstitialPreloadExecutor.stopPreloadAndClear(callbackContext);
254
+ return true;
255
+ }
256
+
257
+ if ("startRewardedPreload".equals(action)) {
258
+ rewardedPreloadExecutor.startPreload(args, callbackContext);
259
+ return true;
260
+ }
261
+
262
+ if ("showPreloadedRewarded".equals(action)) {
263
+ rewardedPreloadExecutor.showPolledAd(args, callbackContext);
264
+ return true;
265
+ }
266
+
267
+ if ("isRewardedAdAvailable".equals(action)) {
268
+ rewardedPreloadExecutor.checkAdAvailable(args, callbackContext);
269
+ return true;
270
+ }
271
+
272
+ if ("stopRewardedPreload".equals(action)) {
273
+ rewardedPreloadExecutor.stopPreloadAndClear(callbackContext);
274
+ return true;
275
+ }
276
+
277
+ if ("startRewardedInterstitialPreload".equals(action)) {
278
+ rewardedInterstitialPreloadExecutor.startPreload(args, callbackContext);
279
+ return true;
280
+ }
281
+
282
+ if ("showPreloadedRewardedInterstitial".equals(action)) {
283
+ rewardedInterstitialPreloadExecutor.showPolledAd(args, callbackContext);
284
+ return true;
285
+ }
286
+
287
+ if ("isRewardedInterstitialAdAvailable".equals(action)) {
288
+ rewardedInterstitialPreloadExecutor.checkAdAvailable(args, callbackContext);
289
+ return true;
290
+ }
291
+
292
+ if ("stopRewardedInterstitialPreload".equals(action)) {
293
+ rewardedInterstitialPreloadExecutor.stopPreloadAndClear(callbackContext);
294
+ return true;
295
+ }
296
+
217
297
  return false;
218
298
  }
219
299
 
@@ -237,7 +317,6 @@ public class AdMobNextGen extends CordovaPlugin {
237
317
  return;
238
318
  }
239
319
 
240
- cordova.getThreadPool().execute(() -> {
241
320
  try {
242
321
  InitializationConfig.Builder initConfigBuilder = new InitializationConfig.Builder(appId);
243
322
 
@@ -262,13 +341,13 @@ public class AdMobNextGen extends CordovaPlugin {
262
341
  cordova.getActivity(),
263
342
  config,
264
343
  initializationStatus -> {
344
+ isInitialized = true;
265
345
  cordova.getActivity().runOnUiThread(() -> callbackContext.success("Initialized"));
266
346
  }
267
347
  );
268
348
  } catch (Exception e) {
269
349
  cordova.getActivity().runOnUiThread(() -> callbackContext.error(e.getMessage()));
270
350
  }
271
- });
272
351
  }
273
352
 
274
353
  private String getAppIdFromManifest() {