emi-indo-cordova-plugin-admob 0.0.1 → 0.0.2
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 +31 -7
- package/example/index.html +56 -3
- 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
@@ -14,25 +14,45 @@
|
|
14
14
|
> - ### No Ad-Sharing
|
15
15
|
> - ### No Remote Control
|
16
16
|
> - ### I guarantee 100% revenue for you.
|
17
|
+
> - [Code source:](https://github.com/googleads/googleads-mobile-android-examples) - Admob:
|
17
18
|
|
18
19
|
|
19
|
-
## Features
|
20
20
|
|
21
|
-
- Banner ads
|
22
|
-
- Interstitial ads
|
23
|
-
- Rewarded ads
|
24
|
-
- Rewarded interstitial ads
|
25
|
-
- App Open Ads (Coming soon)
|
26
21
|
|
22
|
+
https://user-images.githubusercontent.com/78555833/228323239-e9e18e74-b814-4ca8-ab86-b2e28437e61c.mp4
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
## Features
|
28
|
+
|
29
|
+
- Banner Ads
|
30
|
+
- Interstitial Ads
|
31
|
+
- Rewarded Ads
|
32
|
+
- Rewarded interstitial Ads
|
27
33
|
|
34
|
+
## Coming soon
|
35
|
+
- App Open Ads
|
36
|
+
- User Consent
|
37
|
+
- Mediation
|
28
38
|
|
29
39
|
|
30
40
|
## Installation
|
31
41
|
|
32
42
|
```sh
|
33
|
-
emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713
|
43
|
+
cordova plugin add emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713
|
44
|
+
```
|
45
|
+
### Or
|
46
|
+
```sh
|
47
|
+
cordova plugin add https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713
|
48
|
+
```
|
49
|
+
## Remove
|
50
|
+
```sh
|
51
|
+
cordova plugin rm emi-indo-cordova-plugin-admob
|
34
52
|
```
|
35
53
|
|
54
|
+
## 💰Sponsor this project
|
55
|
+
[](https://paypal.me/emiindo)
|
36
56
|
|
37
57
|
## deviceready
|
38
58
|
|
@@ -199,6 +219,10 @@ alert("on Ad Loaded banner");
|
|
199
219
|
- onAdShowedFullScreenContent.rewardedInterstitialAd
|
200
220
|
|
201
221
|
|
222
|
+
### Platform Support
|
223
|
+
- Android
|
224
|
+
|
225
|
+
|
202
226
|
## 💰Sponsor this project
|
203
227
|
[](https://paypal.me/emiindo)
|
204
228
|
|
package/example/index.html
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
/// setting banner size: BANNER | LARGE_BANNER | MEDIUM_RECTANGLE | FULL_BANNER | LEADERBOARD | default: "" = BANNER
|
12
|
-
var size = "
|
12
|
+
var size = "BANNER"
|
13
13
|
/// setting banner position: top-right | top-center | left | center | right | bottom-center | bottom-right | default: "" = bottom-left
|
14
14
|
var position = "bottom-center"
|
15
15
|
|
@@ -34,11 +34,59 @@ document.addEventListener("deviceready", function(){
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
// event
|
37
|
+
// event Sdk initialize
|
38
38
|
|
39
39
|
document.addEventListener('onInitializationComplete', () => {
|
40
40
|
|
41
|
-
alert("on Initialization Complete");
|
41
|
+
alert("on Sdk Initialization Complete");
|
42
|
+
|
43
|
+
});
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
// event On banner load
|
49
|
+
|
50
|
+
document.addEventListener('onAdLoaded.bannerAd', () => {
|
51
|
+
|
52
|
+
alert("on Loaded banner Ad");
|
53
|
+
|
54
|
+
});
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
// event On Interstitial load
|
60
|
+
|
61
|
+
document.addEventListener('onAdLoaded.InterstitialAd', () => {
|
62
|
+
|
63
|
+
alert("on Loaded Interstitial Ad");
|
64
|
+
|
65
|
+
// cordova.plugins.emiAdmobPlugin.showInterstitialAd();
|
66
|
+
|
67
|
+
});
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// event On Rewarded load
|
72
|
+
|
73
|
+
document.addEventListener('onAdLoaded.RewardedAd', () => {
|
74
|
+
|
75
|
+
alert("on Loaded Rewarded Ad");
|
76
|
+
|
77
|
+
// cordova.plugins.emiAdmobPlugin.showRewardedAd();
|
78
|
+
|
79
|
+
});
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
// event On Rewarded Interstitial load
|
84
|
+
|
85
|
+
document.addEventListener('onAdLoaded.RewardedInterstitial', () => {
|
86
|
+
|
87
|
+
alert("on Loaded Rewarded Interstitial");
|
88
|
+
|
89
|
+
// cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd();
|
42
90
|
|
43
91
|
});
|
44
92
|
|
@@ -49,11 +97,16 @@ alert("on Initialization Complete");
|
|
49
97
|
|
50
98
|
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showBannerAd(AdUnitId.bannerAdUnitId, size, position);">Show Banner Ad</button></p>
|
51
99
|
<p> <button onclick="cordova.plugins.emiAdmobPlugin.removeBannerAd();">remove Banner Ad</button></p>
|
100
|
+
|
52
101
|
<p> <button onclick="cordova.plugins.emiAdmobPlugin.loadInterstitialAd(AdUnitId.InterstitialAdAdUnitId);">Load Interstitial Ad</button></p>
|
53
102
|
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showInterstitialAd();">Show Interstitial Ad</button></p>
|
103
|
+
|
54
104
|
<p> <button onclick="cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(AdUnitId.RewardedInterstitialAdUnitId);">Load Rewarded Interstitial</button></p>
|
55
105
|
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd();">Show Rewarded Interstitial</button></p>
|
56
106
|
|
107
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.loadRewardedAd(AdUnitId.RewardedAdAdUnitId);">Load Rewarded Ad</button></p>
|
108
|
+
<p> <button onclick="cordova.plugins.emiAdmobPlugin.showRewardedAd();">Show Rewarded Ad</button></p>
|
109
|
+
|
57
110
|
|
58
111
|
</body>
|
59
112
|
</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.2",
|
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.2">
|
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.json.JSONArray;import org.json.JSONException;import android.util.Log;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaWebView;import org.json.JSONObject;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.OnUserEarnedRewardListener;import com.google.android.gms.ads.initialization.InitializationStatus;import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.rewarded.RewardItem;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private RelativeLayout bannerViewLayout;private AdView bannerView;public void initialize(CordovaInterface cordova,CordovaWebView webView){super.initialize(cordova,webView);cWebView=webView;}public boolean execute(String action,JSONArray args,final CallbackContext callbackContext)throws JSONException{switch(action){case "initialize":cordova.getActivity().runOnUiThread(()-> MobileAds.initialize(cordova.getActivity(),initializationStatus -> cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onInitializationComplete');")));return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String InterstitialAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();InterstitialAd.load(cordova.getActivity(),InterstitialAdAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.InterstitialAd');");mInterstitialAd=interstitialAd;Log.i(TAG,"onAdLoaded");}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());mInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.InterstitialAd');");}});});return true;case "showInterstitialAd":cordova.getActivity().runOnUiThread(()->{mInterstitialAd.show(cordova.getActivity());});return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String RewardedAdAdUnitId=args.optString(0);AdRequest adRequest=new AdRequest.Builder().build();RewardedAd.load(cordova.getActivity(),RewardedAdAdUnitId,adRequest,new RewardedAdLoadCallback(){@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedAd=null;Log.d(TAG,"The rewarded ad wasn't ready yet.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.RewardedAd');");}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;Log.d(TAG,"Ad was loaded.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.RewardedAd');");}});});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(rewardedAd!=null){rewardedAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String RewardedInterstitialAdUnitId=args.optString(0);RewardedInterstitialAd.load(cordova.getActivity(),RewardedInterstitialAdUnitId,new AdRequest.Builder().build(),new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(RewardedInterstitialAd ad){Log.d(TAG,"Ad was loaded.");rewardedInterstitialAd=ad;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.RewardedInterstitial');");}@Override public void onAdFailedToLoad(LoadAdError loadAdError){Log.d(TAG,loadAdError.toString());rewardedInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.RewardedInterstitial');");}});});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(rewardedInterstitialAd!=null){rewardedInterstitialAd.show(cordova.getActivity(),rewardItem ->{Log.d(TAG,"The user earned the reward.");int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();});}else{Log.d(TAG,"The rewarded ad wasn't ready yet.");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{final String bannerAdUnitId=args.optString(0);final String size=args.optString(1);final String position=args.optString(2);if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);bannerViewLayout.setLayoutParams(params);((ViewGroup)Objects.requireNonNull(cWebView.getView())).addView(bannerViewLayout);}bannerView=new AdView(cordova.getActivity());if(Objects.equals(size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else{bannerView.setAdSize(AdSize.BANNER);}bannerView.setAdUnitId(bannerAdUnitId);AdRequest adRequest=new AdRequest.Builder().build();bannerView.loadAd(adRequest);RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}bannerView.setLayoutParams(bannerParams);bannerViewLayout.addView(bannerView);bannerView.setAdListener(new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.bannerAd');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClosed.bannerAd');");}@Override public void onAdFailedToLoad(LoadAdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToLoad.bannerAd');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.bannerAd');");}@Override public void onAdLoaded(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdLoaded.bannerAd');");}@Override public void onAdOpened(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdOpened.bannerAd');");}});});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;ViewGroup parentView=(ViewGroup)bannerView.getParent();if(parentView!=null){parentView.removeView(bannerView);bannerView.destroy();bannerView=null;}});return true;}mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.InterstitialAd');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");mInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdDismissedFullScreenContent.InterstitialAd');");}@Override public void onAdFailedToShowFullScreenContent(AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");mInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToShowFullScreenContent.InterstitialAd');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.InterstitialAd');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdShowedFullScreenContent.InterstitialAd');");}});rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.rewardedAd');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdDismissedFullScreenContent.rewardedAd');");}@Override public void onAdFailedToShowFullScreenContent(AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToShowFullScreenContent.rewardedAd');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.rewardedAd');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdShowedFullScreenContent.rewardedAd');");}});rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){Log.d(TAG,"Ad was clicked.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdClicked.rewardedInterstitialAd');");}@Override public void onAdDismissedFullScreenContent(){Log.d(TAG,"Ad dismissed fullscreen content.");rewardedInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdDismissedFullScreenContent.rewardedInterstitialAd');");}@Override public void onAdFailedToShowFullScreenContent(AdError adError){Log.e(TAG,"Ad failed to show fullscreen content.");rewardedInterstitialAd=null;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdFailedToShowFullScreenContent.rewardedInterstitialAd');");}@Override public void onAdImpression(){Log.d(TAG,"Ad recorded an impression.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdImpression.rewardedInterstitialAd');");}@Override public void onAdShowedFullScreenContent(){Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('onAdShowedFullScreenContent.rewardedInterstitialAd');");}});return false;}}
|