cordova-plugin-admob-nextgen 1.0.0
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 +21 -0
- package/README.md +458 -0
- package/capacitor-hook-admob-ids.js +109 -0
- package/package.json +42 -0
- package/plugin.xml +53 -0
- package/src/android/AdMobNextGen.java +306 -0
- package/src/android/AppOpenAdExecutor.java +246 -0
- package/src/android/BannerExecutor.java +447 -0
- package/src/android/BannerPreloadExecutor.java +364 -0
- package/src/android/ConsentExecutor.java +279 -0
- package/src/android/GlobalSettingsExecutor.java +139 -0
- package/src/android/InterstitialExecutor.java +223 -0
- package/src/android/NativeExecutor.java +422 -0
- package/src/android/RewardedExecutor.java +239 -0
- package/src/android/RewardedInterstitialExecutor.java +210 -0
- package/src/android/hooks/admob-nextgen.gradle +12 -0
- package/www/admob-nextgen.js +118 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
package com.emi.cordova.admob.nextgen;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
|
|
8
|
+
import org.apache.cordova.CallbackContext;
|
|
9
|
+
import org.apache.cordova.CordovaInterface;
|
|
10
|
+
import org.apache.cordova.CordovaWebView;
|
|
11
|
+
import org.json.JSONArray;
|
|
12
|
+
import org.json.JSONException;
|
|
13
|
+
import org.json.JSONObject;
|
|
14
|
+
|
|
15
|
+
import java.util.Date;
|
|
16
|
+
|
|
17
|
+
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback;
|
|
18
|
+
import com.google.android.libraries.ads.mobile.sdk.common.AdRequest;
|
|
19
|
+
import com.google.android.libraries.ads.mobile.sdk.common.AdValue;
|
|
20
|
+
import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError;
|
|
21
|
+
import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError;
|
|
22
|
+
|
|
23
|
+
import com.google.android.libraries.ads.mobile.sdk.rewardedinterstitial.RewardedInterstitialAd;
|
|
24
|
+
import com.google.android.libraries.ads.mobile.sdk.rewardedinterstitial.RewardedInterstitialAdEventCallback;
|
|
25
|
+
|
|
26
|
+
public class RewardedInterstitialExecutor {
|
|
27
|
+
|
|
28
|
+
private static final String TAG = "AdMobRewInter";
|
|
29
|
+
private CordovaInterface cordova;
|
|
30
|
+
private CordovaWebView webView;
|
|
31
|
+
|
|
32
|
+
private RewardedInterstitialAd mRewardedInterstitialAd;
|
|
33
|
+
|
|
34
|
+
private boolean isAutoShow = false;
|
|
35
|
+
|
|
36
|
+
private boolean isLoading = false;
|
|
37
|
+
private long lastLoadTime = 0;
|
|
38
|
+
private long minLoadInterval = 5000;
|
|
39
|
+
|
|
40
|
+
public RewardedInterstitialExecutor(CordovaInterface cordova, CordovaWebView webView) {
|
|
41
|
+
this.cordova = cordova;
|
|
42
|
+
this.webView = webView;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public void createRewardedInterstitial(JSONArray args, CallbackContext callbackContext) {
|
|
46
|
+
try {
|
|
47
|
+
JSONObject options = args.getJSONObject(0);
|
|
48
|
+
String adUnitId = options.getString("adUnitId");
|
|
49
|
+
this.isAutoShow = options.optBoolean("isAutoShow", false);
|
|
50
|
+
|
|
51
|
+
if (options.has("retryInterval")) {
|
|
52
|
+
this.minLoadInterval = options.getLong("retryInterval");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
long currentTime = new Date().getTime();
|
|
56
|
+
|
|
57
|
+
if (isLoading) {
|
|
58
|
+
|
|
59
|
+
callbackContext.error("Ad is loading");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if ((currentTime - lastLoadTime) < minLoadInterval) {
|
|
64
|
+
|
|
65
|
+
callbackContext.error("Request too fast");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
isLoading = true;
|
|
70
|
+
lastLoadTime = currentTime;
|
|
71
|
+
|
|
72
|
+
cordova.getActivity().runOnUiThread(() -> {
|
|
73
|
+
loadAd(adUnitId, callbackContext);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
} catch (JSONException e) {
|
|
77
|
+
callbackContext.error("Invalid Args: " + e.getMessage());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private void loadAd(String adUnitId, CallbackContext callbackContext) {
|
|
82
|
+
AdRequest adRequest = new AdRequest.Builder(adUnitId).build();
|
|
83
|
+
|
|
84
|
+
RewardedInterstitialAd.load(
|
|
85
|
+
adRequest,
|
|
86
|
+
new AdLoadCallback<RewardedInterstitialAd>() {
|
|
87
|
+
@Override
|
|
88
|
+
public void onAdLoaded(@NonNull RewardedInterstitialAd ad) {
|
|
89
|
+
isLoading = false;
|
|
90
|
+
mRewardedInterstitialAd = ad;
|
|
91
|
+
|
|
92
|
+
fireEvent("on.rewardedInter.loaded", null);
|
|
93
|
+
|
|
94
|
+
if (isAutoShow) {
|
|
95
|
+
showRewardedInterstitial(callbackContext);
|
|
96
|
+
} else {
|
|
97
|
+
callbackContext.success("Ad Loaded");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Override
|
|
102
|
+
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
|
|
103
|
+
isLoading = false;
|
|
104
|
+
|
|
105
|
+
mRewardedInterstitialAd = null;
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
JSONObject err = new JSONObject();
|
|
109
|
+
err.put("code", loadAdError.getCode());
|
|
110
|
+
err.put("message", loadAdError.getMessage());
|
|
111
|
+
fireEvent("on.rewardedInter.failed.load", err);
|
|
112
|
+
} catch (JSONException e) {}
|
|
113
|
+
|
|
114
|
+
callbackContext.error(loadAdError.getMessage());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public void showRewardedInterstitial(CallbackContext callbackContext) {
|
|
121
|
+
cordova.getActivity().runOnUiThread(() -> {
|
|
122
|
+
if (mRewardedInterstitialAd != null) {
|
|
123
|
+
|
|
124
|
+
mRewardedInterstitialAd.setAdEventCallback(new RewardedInterstitialAdEventCallback() {
|
|
125
|
+
|
|
126
|
+
@Override
|
|
127
|
+
public void onAdPaid(@NonNull AdValue adValue) {
|
|
128
|
+
try {
|
|
129
|
+
JSONObject data = new JSONObject();
|
|
130
|
+
data.put("value", adValue.getValueMicros());
|
|
131
|
+
data.put("currency", adValue.getCurrencyCode());
|
|
132
|
+
data.put("precision", adValue.getPrecisionType());
|
|
133
|
+
|
|
134
|
+
fireEvent("on.rewardedInter.revenue", data);
|
|
135
|
+
} catch (JSONException e) {
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@Override
|
|
141
|
+
public void onAdShowedFullScreenContent() {
|
|
142
|
+
|
|
143
|
+
fireEvent("on.rewardedInter.shown", null);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@Override
|
|
147
|
+
public void onAdDismissedFullScreenContent() {
|
|
148
|
+
|
|
149
|
+
fireEvent("on.rewardedInter.dismissed", null);
|
|
150
|
+
mRewardedInterstitialAd = null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@Override
|
|
154
|
+
public void onAdFailedToShowFullScreenContent(@NonNull FullScreenContentError error) {
|
|
155
|
+
|
|
156
|
+
mRewardedInterstitialAd = null;
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
JSONObject err = new JSONObject();
|
|
160
|
+
err.put("message", error.getMessage());
|
|
161
|
+
fireEvent("on.rewardedInter.failed.show", err);
|
|
162
|
+
} catch (JSONException e) {}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@Override
|
|
166
|
+
public void onAdImpression() {
|
|
167
|
+
fireEvent("on.rewardedInter.impression", null);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Override
|
|
171
|
+
public void onAdClicked() {
|
|
172
|
+
fireEvent("on.rewardedInter.clicked", null);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
Activity activity = cordova.getActivity();
|
|
177
|
+
mRewardedInterstitialAd.show(activity, rewardItem -> {
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
JSONObject data = new JSONObject();
|
|
181
|
+
data.put("amount", rewardItem.getAmount());
|
|
182
|
+
data.put("type", rewardItem.getType());
|
|
183
|
+
fireEvent("on.rewardedInter.earned", data);
|
|
184
|
+
} catch (JSONException e) {}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
if (callbackContext != null) callbackContext.success("Ad Shown");
|
|
188
|
+
|
|
189
|
+
} else {
|
|
190
|
+
|
|
191
|
+
if (callbackContext != null) callbackContext.error("Ad Not Ready");
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private void fireEvent(String eventName, JSONObject data) {
|
|
197
|
+
cordova.getActivity().runOnUiThread(() -> {
|
|
198
|
+
StringBuilder js = new StringBuilder();
|
|
199
|
+
js.append("javascript:cordova.fireDocumentEvent('");
|
|
200
|
+
js.append(eventName);
|
|
201
|
+
js.append("'");
|
|
202
|
+
if (data != null) {
|
|
203
|
+
js.append(", ");
|
|
204
|
+
js.append(data.toString());
|
|
205
|
+
}
|
|
206
|
+
js.append(");");
|
|
207
|
+
if (webView != null) webView.loadUrl(js.toString());
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// https://developers.google.com/admob/android/next-gen/migration#exclude_comgoogleandroidgms_modules_in_mediation_integrations
|
|
2
|
+
|
|
3
|
+
repositories {
|
|
4
|
+
google()
|
|
5
|
+
mavenCentral()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Prevent conflicts with legacy SDKs when using mediation
|
|
9
|
+
configurations.configureEach {
|
|
10
|
+
exclude group: "com.google.android.gms", module: "play-services-ads"
|
|
11
|
+
exclude group: "com.google.android.gms", module: "play-services-ads-lite"
|
|
12
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var exec = require('cordova/exec');
|
|
2
|
+
|
|
3
|
+
var AdMobNextGen = {
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Created by EMI INDO So on Frb 10, 2026
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
setAppVolume: function (volume, success, error) {
|
|
10
|
+
exec(success, error, 'AdMobNextGen', 'setAppVolume', [volume]);
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
setAppMuted: function (muted, success, error) {
|
|
14
|
+
exec(success, error, 'AdMobNextGen', 'setAppMuted', [muted]);
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
setRequestConfiguration: function (config, success, error) {
|
|
18
|
+
exec(success, error, 'AdMobNextGen', 'setRequestConfiguration', [config]);
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
requestConsentInfo: function (options, success, error) {
|
|
22
|
+
exec(success, error, 'AdMobNextGen', 'requestConsentInfo', [options]);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
showPrivacyOptionsForm: function (success, error) {
|
|
26
|
+
exec(success, error, 'AdMobNextGen', 'showPrivacyOptionsForm', []);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
getTCData: function (success, error) {
|
|
30
|
+
exec(success, error, 'AdMobNextGen', 'getTCData', []);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// Inisialisasi SDK
|
|
34
|
+
initialize: function (config, success, error) {
|
|
35
|
+
var args = [];
|
|
36
|
+
var successCb = success;
|
|
37
|
+
var errorCb = error;
|
|
38
|
+
|
|
39
|
+
if (typeof config === 'function') {
|
|
40
|
+
successCb = config;
|
|
41
|
+
errorCb = success;
|
|
42
|
+
} else if (config && typeof config === 'object') {
|
|
43
|
+
args = [config];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exec(successCb, errorCb, 'AdMobNextGen', 'initialize', args);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
createBanner: function (options, success, error) {
|
|
50
|
+
exec(success, error, 'AdMobNextGen', 'createBanner', [options]);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
hideBanner: function (success, error) {
|
|
54
|
+
exec(success, error, 'AdMobNextGen', 'hideBanner', []);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
showBanner: function (success, error) {
|
|
58
|
+
exec(success, error, 'AdMobNextGen', 'showBanner', []);
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
removeBanner: function (success, error) {
|
|
62
|
+
exec(success, error, 'AdMobNextGen', 'removeBanner', []);
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
createInterstitial: function (options, successEvent, error) {
|
|
66
|
+
exec(successEvent, error, 'AdMobNextGen', 'createInterstitial', [options]);
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
showInterstitial: function (success, error) {
|
|
70
|
+
exec(success, error, 'AdMobNextGen', 'showInterstitial', []);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
createRewarded: function (options, successEvent, error) {
|
|
74
|
+
exec(successEvent, error, 'AdMobNextGen', 'createRewarded', [options]);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
showRewarded: function (success, error) {
|
|
78
|
+
exec(success, error, 'AdMobNextGen', 'showRewarded', []);
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
createRewardedInterstitial: function (options, success, error) {
|
|
82
|
+
exec(success, error, 'AdMobNextGen', 'createRewardedInterstitial', [options]);
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
showRewardedInterstitial: function (success, error) {
|
|
86
|
+
exec(success, error, 'AdMobNextGen', 'showRewardedInterstitial', []);
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
loadAppOpenAd: function (options, successEvent, error) {
|
|
90
|
+
exec(successEvent, error, 'AdMobNextGen', 'loadAppOpenAd', [options]);
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
showAppOpenAd: function (success, error) {
|
|
94
|
+
exec(success, error, 'AdMobNextGen', 'showAppOpenAd', []);
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
createNativeAd: function (options, successEvent, error) {
|
|
98
|
+
exec(successEvent, error, 'AdMobNextGen', 'createNativeAd', [options]);
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
removeNativeAd: function (success, error) {
|
|
102
|
+
exec(success, error, 'AdMobNextGen', 'removeNativeAd', []);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
startBannerPreload: function (options, success, error) {
|
|
106
|
+
exec(success, error, 'AdMobNextGen', 'startBannerPreload', [options]);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
showPreloadedBanner: function (options, success, error) {
|
|
110
|
+
exec(success, error, 'AdMobNextGen', 'showPreloadedBanner', [options]);
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
stopBannerPreload: function (success, error) {
|
|
114
|
+
exec(success, error, 'AdMobNextGen', 'stopBannerPreload', []);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
module.exports = AdMobNextGen;
|