cordova-plugin-admob-nextgen 2.0.2 → 2.0.3-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-admob-nextgen",
3
- "version": "2.0.2",
3
+ "version": "2.0.3-beta.1",
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="2.0.2"
3
+ version="2.0.3-beta.1"
4
4
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
5
5
  xmlns:android="http://schemas.android.com/apk/res/android">
6
6
 
@@ -52,6 +52,7 @@ public class AdMobNextGen extends CordovaPlugin {
52
52
 
53
53
  private boolean isNativeValidatorDisabled = true;
54
54
  public static boolean isInitialized = false;
55
+ public static boolean isAppInForeground = true;
55
56
 
56
57
  @Override
57
58
  public void pluginInitialize() {
@@ -300,6 +301,7 @@ public class AdMobNextGen extends CordovaPlugin {
300
301
  @Override
301
302
  public void onResume(boolean multitasking) {
302
303
  super.onResume(multitasking);
304
+ isAppInForeground = true;
303
305
  if (appOpenAdExecutor != null && appOpenAdExecutor.shouldAutoShow()) {
304
306
  appOpenAdExecutor.showAdIfAvailable(cordova.getActivity());
305
307
  }
@@ -310,6 +312,12 @@ public class AdMobNextGen extends CordovaPlugin {
310
312
  }
311
313
  }
312
314
 
315
+ @Override
316
+ public void onPause(boolean multitasking) {
317
+ super.onPause(multitasking);
318
+ isAppInForeground = false;
319
+ }
320
+
313
321
  private void initializeSDK(JSONArray args, CallbackContext callbackContext) {
314
322
  String appId = getAppIdFromManifest();
315
323
  if (appId == null) {
@@ -203,10 +203,23 @@ public class AppOpenAdExecutor {
203
203
  }
204
204
  });
205
205
 
206
- isShowingAd = true;
207
206
  cordova.getActivity().runOnUiThread(() -> {
207
+
208
+ if (!AdMobNextGen.isAppInForeground) {
209
+ try {
210
+ JSONObject errData = new JSONObject();
211
+ errData.put("code", "APP_IN_BACKGROUND");
212
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
213
+ fireEvent("on.appopen.failed.show", errData);
214
+ } catch (JSONException e) {}
215
+
216
+ return;
217
+ }
218
+
219
+ isShowingAd = true;
208
220
  appOpenAd.show(activity);
209
221
  });
222
+
210
223
  }
211
224
 
212
225
  public boolean shouldAutoShow() {
@@ -84,6 +84,11 @@ public class InterstitialExecutor {
84
84
  requestCallback.success("Ad already loaded and ready");
85
85
  }
86
86
  fireEvent("on.interstitial.loaded", null);
87
+
88
+ if (isAutoShow) {
89
+ showInterstitialAd();
90
+ }
91
+
87
92
  return;
88
93
  }
89
94
 
@@ -115,6 +120,7 @@ public class InterstitialExecutor {
115
120
  if (isAutoShow) {
116
121
  showInterstitialAd();
117
122
  }
123
+
118
124
  }
119
125
 
120
126
  @Override
@@ -152,6 +158,17 @@ public class InterstitialExecutor {
152
158
  Activity activity = cordova.getActivity();
153
159
 
154
160
  activity.runOnUiThread(() -> {
161
+
162
+ if (!AdMobNextGen.isAppInForeground) {
163
+ try {
164
+ JSONObject errData = new JSONObject();
165
+ errData.put("code", "APP_IN_BACKGROUND");
166
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
167
+ fireEvent("on.interstitial.failed.show", errData);
168
+ } catch (JSONException e) {}
169
+ return;
170
+ }
171
+
155
172
  interstitialAd.setAdEventCallback(new InterstitialAdEventCallback() {
156
173
 
157
174
  @Override
@@ -84,6 +84,11 @@ public class RewardedExecutor {
84
84
  if (rewardedAd != null) {
85
85
 
86
86
  fireEvent("on.rewarded.loaded", null);
87
+
88
+ if (isAutoShow) {
89
+ showRewardedAd();
90
+ }
91
+
87
92
  return;
88
93
  }
89
94
 
@@ -155,6 +160,16 @@ public class RewardedExecutor {
155
160
 
156
161
  isRewardEarned = false;
157
162
 
163
+ if (!AdMobNextGen.isAppInForeground) {
164
+ try {
165
+ JSONObject errData = new JSONObject();
166
+ errData.put("code", "APP_IN_BACKGROUND");
167
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
168
+ fireEvent("on.rewarded.failed.show", errData);
169
+ } catch (JSONException e) {}
170
+ return;
171
+ }
172
+
158
173
  rewardedAd.setAdEventCallback(new RewardedAdEventCallback() {
159
174
 
160
175
  @Override
@@ -73,6 +73,11 @@ public class RewardedInterstitialExecutor {
73
73
  if (callbackContext != null) {
74
74
  callbackContext.success("Ad already loaded");
75
75
  }
76
+
77
+ if (isAutoShow) {
78
+ showRewardedInterstitial(null);
79
+ }
80
+
76
81
  return;
77
82
  }
78
83
 
@@ -138,6 +143,16 @@ public class RewardedInterstitialExecutor {
138
143
 
139
144
  isRewardEarned = false;
140
145
 
146
+ if (!AdMobNextGen.isAppInForeground) {
147
+ try {
148
+ JSONObject errData = new JSONObject();
149
+ errData.put("code", "APP_IN_BACKGROUND");
150
+ errData.put("message", "Ad presentation blocked: Application is currently in the background.");
151
+ fireEvent("on.rewardedInter.failed.show", errData);
152
+ } catch (JSONException e) {}
153
+ return;
154
+ }
155
+
141
156
  mRewardedInterstitialAd.setAdEventCallback(new RewardedInterstitialAdEventCallback() {
142
157
 
143
158
  @Override