emi-indo-cordova-plugin-admob 2.0.1 → 2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Cordova/Quasar/Capacitor Plugin Admob Android IOS",
5
5
  "cordova": {
6
6
  "id": "emi-indo-cordova-plugin-admob",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2
2
  xmlns:android="http://schemas.android.com/apk/res/android"
3
- id="emi-indo-cordova-plugin-admob" version="2.0.1">
3
+ id="emi-indo-cordova-plugin-admob" version="2.0.2">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova/Quasar/Capacitor Plugin Admob Android IOS</description>
@@ -52,7 +52,7 @@
52
52
  <meta-data android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
53
53
  android:value="true" />
54
54
  <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION"
55
- android:value="true" />
55
+ android:value="false" />
56
56
  <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
57
57
  android:value="true" />
58
58
  <meta-data
@@ -111,8 +111,7 @@ class emiAdmobPlugin : CordovaPlugin() {
111
111
  private var isCollapsible: Boolean = false
112
112
  var lock: Boolean = true
113
113
  private var setDebugGeography: Boolean = false
114
- private var mActivity: Activity? = null
115
- private var mContext: Context? = null
114
+
116
115
  private var mInterstitialAd: InterstitialAd? = null
117
116
  private var appOpenAd: AppOpenAd? = null
118
117
  private var isOrientation: Int = 1
@@ -145,55 +144,64 @@ class emiAdmobPlugin : CordovaPlugin() {
145
144
 
146
145
  private var isCustomConsentManager = false
147
146
 
147
+ private var mActivity: Activity? = null
148
+ private var mContext: Context? = null
149
+
148
150
 
149
151
  override fun initialize(cordova: CordovaInterface, webView: CordovaWebView) {
150
152
  super.initialize(cordova, webView)
153
+
151
154
  cWebView = webView
152
- mActivity = this.cordova.activity
153
- mActivity?.let {
154
- mContext = it.applicationContext
155
- }
155
+ mActivity = cordova.activity
156
+
157
+ if (mActivity != null) {
156
158
 
157
- mPreferences = mContext?.let { PreferenceManager.getDefaultSharedPreferences(it) }
159
+ mContext = mActivity?.applicationContext
158
160
 
161
+ mPreferences = mContext?.let { PreferenceManager.getDefaultSharedPreferences(it) }
162
+
163
+ } else {
164
+ Log.e("PluginCordova", "Activity is null during initialization")
165
+ }
159
166
  }
160
167
 
161
168
 
162
169
 
170
+
163
171
  override fun onConfigurationChanged(newConfig: Configuration) {
164
172
  super.onConfigurationChanged(newConfig)
165
173
  val orientation = newConfig.orientation
166
174
  if (orientation != isOrientation) {
167
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.screen.rotated');")
175
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.screen.rotated');")
168
176
  isOrientation = orientation
169
177
  if (this.isAutoResize) {
170
178
  if(mActivity != null) {
171
- mActivity!!.runOnUiThread {
179
+ mActivity?.runOnUiThread {
172
180
  try {
173
181
  bannerOverlappingToZero()
174
182
  if (bannerViewLayout != null && bannerView != null) {
175
- val parentView = bannerViewLayout!!.parent as ViewGroup
183
+ val parentView = bannerViewLayout?.parent as ViewGroup
176
184
  parentView.removeView(bannerViewLayout)
177
185
  bannerViewLayout = FrameLayout(mActivity!!)
178
186
  val params = FrameLayout.LayoutParams(
179
187
  FrameLayout.LayoutParams.MATCH_PARENT,
180
188
  FrameLayout.LayoutParams.WRAP_CONTENT
181
189
  )
182
- val decorView = mActivity!!.window.decorView as ViewGroup
190
+ val decorView = mActivity?.window?.decorView as ViewGroup
183
191
  decorView.addView(bannerViewLayout, params)
184
192
  bannerView = AdView(mActivity!!)
185
193
  setBannerPosition(this.isPosition)
186
194
  setBannerSize(this.isSize)
187
- bannerView!!.adUnitId = bannerAdUnitId!!
188
- bannerView!!.adListener = bannerAdListener
189
- bannerView!!.loadAd(buildAdRequest())
190
- bannerViewLayout!!.addView(bannerView)
191
- bannerViewLayout!!.bringToFront()
192
- bannerViewLayout!!.requestFocus();
195
+ bannerView?.adUnitId = bannerAdUnitId!!
196
+ bannerView?.adListener = bannerAdListener
197
+ bannerView?.loadAd(buildAdRequest())
198
+ bannerViewLayout?.addView(bannerView)
199
+ bannerViewLayout?.bringToFront()
200
+ bannerViewLayout?.requestFocus();
193
201
  bannerOverlappingToZero()
194
202
  }
195
203
  } catch (e: Exception) {
196
- PUBLIC_CALLBACKS!!.error("Error adjusting banner size: " + e.message)
204
+ PUBLIC_CALLBACKS?.error("Error adjusting banner size: " + e.message)
197
205
  }
198
206
  }
199
207
  }
@@ -204,16 +212,16 @@ class emiAdmobPlugin : CordovaPlugin() {
204
212
  if (isOverlapping) {
205
213
  bannerOverlapping()
206
214
  }
207
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
215
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
208
216
  }
209
217
  Configuration.ORIENTATION_LANDSCAPE -> {
210
218
  if (isOverlapping) {
211
219
  bannerOverlapping()
212
220
  }
213
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
221
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
214
222
  }
215
223
  Configuration.ORIENTATION_UNDEFINED -> {
216
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.undefined');")
224
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.undefined');")
217
225
  }
218
226
 
219
227
 
@@ -411,7 +419,7 @@ class emiAdmobPlugin : CordovaPlugin() {
411
419
  } else if (action == "loadAppOpenAd") {
412
420
  val options = args.getJSONObject(0)
413
421
  if (mActivity != null) {
414
- mActivity!!.runOnUiThread {
422
+ mActivity?.runOnUiThread {
415
423
  val adUnitId = options.optString("adUnitId")
416
424
  val autoShow = options.optBoolean("autoShow")
417
425
  try {
@@ -428,7 +436,7 @@ class emiAdmobPlugin : CordovaPlugin() {
428
436
  openAutoShow()
429
437
  }
430
438
 
431
- cWebView!!.loadUrl(
439
+ cWebView?.loadUrl(
432
440
  "javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');"
433
441
  )
434
442
 
@@ -465,7 +473,7 @@ class emiAdmobPlugin : CordovaPlugin() {
465
473
  result.put("getResponseExtras", responseInfo?.responseExtras.toString())
466
474
  result.put("getMediationAdapterClassName", responseInfo?.mediationAdapterClassName.toString())
467
475
  result.put("getBundleExtra", mBundleExtra.toString())
468
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.responseInfo', ${result})")
476
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.responseInfo', ${result})")
469
477
  } catch (e: JSONException) {
470
478
  callbackContext.error(e.message)
471
479
  }
@@ -479,14 +487,14 @@ class emiAdmobPlugin : CordovaPlugin() {
479
487
  private fun openAutoShow() {
480
488
  try {
481
489
  if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
482
- mActivity!!.runOnUiThread {
483
- appOpenAd!!.show(
490
+ mActivity?.runOnUiThread {
491
+ appOpenAd?.show(
484
492
  mActivity!!
485
- )
493
+ ) ?: callbackContext.error("Failed to show App Open Ad")
486
494
  }
487
495
  }
488
496
  } catch (e: Exception) {
489
- PUBLIC_CALLBACKS!!.error(e.toString())
497
+ PUBLIC_CALLBACKS?.error(e.toString())
490
498
  }
491
499
  }
492
500
 
@@ -526,7 +534,7 @@ class emiAdmobPlugin : CordovaPlugin() {
526
534
 
527
535
  try {
528
536
  if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
529
- mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
537
+ mActivity?.runOnUiThread { appOpenAd?.show(mActivity!!) ?: callbackContext.error("Failed to show App Open Ad") }
530
538
  appOpenAdLoadCallback()
531
539
  } else {
532
540
  callbackContext.error("The App Open Ad wasn't ready yet")
@@ -539,7 +547,7 @@ class emiAdmobPlugin : CordovaPlugin() {
539
547
  } else if (action == "loadInterstitialAd") {
540
548
  val options = args.getJSONObject(0)
541
549
  if (mActivity != null) {
542
- mActivity!!.runOnUiThread {
550
+ mActivity?.runOnUiThread {
543
551
  val adUnitId = options.optString("adUnitId")
544
552
  val autoShow = options.optBoolean("autoShow")
545
553
  try {
@@ -555,7 +563,7 @@ class emiAdmobPlugin : CordovaPlugin() {
555
563
  isIntAutoShow
556
564
  }
557
565
 
558
- cWebView!!.loadUrl(
566
+ cWebView?.loadUrl(
559
567
  "javascript:cordova.fireDocumentEvent('on.interstitial.loaded');"
560
568
  )
561
569
 
@@ -590,7 +598,7 @@ class emiAdmobPlugin : CordovaPlugin() {
590
598
  result.put("currency", currencyCode)
591
599
  result.put("precision", precision)
592
600
  result.put("adUnitId", interstitialAdUnitId)
593
- cWebView!!.loadUrl(
601
+ cWebView?.loadUrl(
594
602
  "javascript:cordova.fireDocumentEvent('on.interstitial.revenue', ${result});"
595
603
  )
596
604
 
@@ -604,10 +612,10 @@ class emiAdmobPlugin : CordovaPlugin() {
604
612
  private val isIntAutoShow: Unit
605
613
  get() {
606
614
  if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
607
- mActivity!!.runOnUiThread {
608
- mInterstitialAd!!.show(
615
+ mActivity?.runOnUiThread {
616
+ mInterstitialAd?.show(
609
617
  mActivity!!
610
- )
618
+ ) ?: callbackContext.error("Failed to show Interstitial Ad")
611
619
  }
612
620
  }
613
621
  }
@@ -635,7 +643,7 @@ class emiAdmobPlugin : CordovaPlugin() {
635
643
  put("responseInfoAdapterResponses", adapterResponses)
636
644
  }
637
645
 
638
- cWebView!!.loadUrl(
646
+ cWebView?.loadUrl(
639
647
  "javascript:cordova.fireDocumentEvent('on.interstitial.failed.load', ${errorData});"
640
648
  )
641
649
 
@@ -650,7 +658,7 @@ class emiAdmobPlugin : CordovaPlugin() {
650
658
  } else if (action == "showInterstitialAd") {
651
659
 
652
660
  if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
653
- mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
661
+ mActivity?.runOnUiThread { mInterstitialAd?.show(mActivity!!) ?: callbackContext.error("Failed to show Interstitial Ad") }
654
662
  interstitialAdLoadCallback()
655
663
  } else {
656
664
  callbackContext.error("The Interstitial ad wasn't ready yet")
@@ -659,7 +667,7 @@ class emiAdmobPlugin : CordovaPlugin() {
659
667
  } else if (action == "loadRewardedAd") {
660
668
  val options = args.getJSONObject(0)
661
669
  if (mActivity != null) {
662
- mActivity!!.runOnUiThread {
670
+ mActivity?.runOnUiThread {
663
671
  val adUnitId = options.optString("adUnitId")
664
672
  val autoShow = options.optBoolean("autoShow")
665
673
  try {
@@ -692,7 +700,7 @@ class emiAdmobPlugin : CordovaPlugin() {
692
700
 
693
701
  }
694
702
 
695
- cWebView!!.loadUrl(
703
+ cWebView?.loadUrl(
696
704
  "javascript:cordova.fireDocumentEvent('on.rewarded.failed.load', ${errorData});"
697
705
  )
698
706
 
@@ -709,7 +717,7 @@ class emiAdmobPlugin : CordovaPlugin() {
709
717
 
710
718
  rewardedAdLoadCallback()
711
719
 
712
- cWebView!!.loadUrl(
720
+ cWebView?.loadUrl(
713
721
  "javascript:cordova.fireDocumentEvent('on.rewarded.loaded');"
714
722
  )
715
723
 
@@ -725,7 +733,7 @@ class emiAdmobPlugin : CordovaPlugin() {
725
733
  result.put("currency", currencyCode)
726
734
  result.put("precision", precision)
727
735
  result.put("adUnitId", rewardedAdAdUnitId)
728
- cWebView!!.loadUrl(
736
+ cWebView?.loadUrl(
729
737
  "javascript:cordova.fireDocumentEvent('on.rewarded.revenue', ${result});"
730
738
  )
731
739
  } catch (e: JSONException) {
@@ -757,10 +765,10 @@ class emiAdmobPlugin : CordovaPlugin() {
757
765
  private val isRewardedAutoShow: Unit
758
766
  get() {
759
767
  if (mActivity != null) {
760
- mActivity!!.runOnUiThread {
768
+ mActivity?.runOnUiThread {
761
769
  if (isRewardedLoad && rewardedAd != null) {
762
770
  isAdSkip = 1
763
- rewardedAd!!.show(mActivity!!) { rewardItem: RewardItem ->
771
+ rewardedAd?.show(mActivity!!) { rewardItem: RewardItem ->
764
772
  isAdSkip = 2
765
773
  val rewardAmount = rewardItem.amount
766
774
  val rewardType = rewardItem.type
@@ -768,7 +776,7 @@ class emiAdmobPlugin : CordovaPlugin() {
768
776
  try {
769
777
  result.put("rewardType", rewardType)
770
778
  result.put("rewardAmount", rewardAmount)
771
- cWebView!!.loadUrl(
779
+ cWebView?.loadUrl(
772
780
  "javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});"
773
781
  )
774
782
  } catch (e: JSONException) {
@@ -789,9 +797,9 @@ class emiAdmobPlugin : CordovaPlugin() {
789
797
  return true
790
798
  } else if (action == "showRewardedAd") {
791
799
  if (mActivity != null && isRewardedLoad && rewardedAd != null) {
792
- mActivity!!.runOnUiThread {
800
+ mActivity?.runOnUiThread {
793
801
  isAdSkip = 1
794
- rewardedAd!!.show(mActivity!!) { rewardItem: RewardItem ->
802
+ rewardedAd?.show(mActivity!!) { rewardItem: RewardItem ->
795
803
  isAdSkip = 2
796
804
  val rewardAmount = rewardItem.amount
797
805
  val rewardType = rewardItem.type
@@ -799,7 +807,7 @@ class emiAdmobPlugin : CordovaPlugin() {
799
807
  try {
800
808
  result.put("rewardType", rewardType)
801
809
  result.put("rewardAmount", rewardAmount)
802
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});")
810
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});")
803
811
  } catch (e: JSONException) {
804
812
  callbackContext.error(e.message)
805
813
  }
@@ -816,7 +824,7 @@ class emiAdmobPlugin : CordovaPlugin() {
816
824
  } else if (action == "loadRewardedInterstitialAd") {
817
825
  val options = args.getJSONObject(0)
818
826
  if (mActivity != null) {
819
- mActivity!!.runOnUiThread {
827
+ mActivity?.runOnUiThread {
820
828
  val adUnitId = options.optString("adUnitId")
821
829
  val autoShow = options.optBoolean("autoShow")
822
830
  try {
@@ -829,7 +837,7 @@ class emiAdmobPlugin : CordovaPlugin() {
829
837
  isRewardedInterstitialLoad = true
830
838
  isAdSkip = 0
831
839
 
832
- cWebView!!.loadUrl(
840
+ cWebView?.loadUrl(
833
841
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');"
834
842
  )
835
843
 
@@ -870,7 +878,7 @@ class emiAdmobPlugin : CordovaPlugin() {
870
878
  result.put("getResponseExtras", responseInfo?.responseExtras)
871
879
  result.put("getMediationAdapterClassName", responseInfo?.mediationAdapterClassName)
872
880
  result.put("getBundleExtra", mBundleExtra.toString())
873
- cWebView!!.loadUrl(
881
+ cWebView?.loadUrl(
874
882
  "javascript:cordova.fireDocumentEvent('on.rewardedIntAd.responseInfo', ${result});"
875
883
  )
876
884
  } catch (e: JSONException) {
@@ -885,10 +893,10 @@ class emiAdmobPlugin : CordovaPlugin() {
885
893
  private val isRIntAutoShow: Unit
886
894
  get() {
887
895
  if (mActivity !== null) {
888
- mActivity!!.runOnUiThread {
896
+ mActivity?.runOnUiThread {
889
897
  if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
890
898
  isAdSkip = 1
891
- rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
899
+ rewardedInterstitialAd?.show(mActivity!!) { rewardItem: RewardItem ->
892
900
  isAdSkip = 2
893
901
  val rewardAmount = rewardItem.amount
894
902
  val rewardType = rewardItem.type
@@ -896,7 +904,7 @@ class emiAdmobPlugin : CordovaPlugin() {
896
904
  try {
897
905
  result.put("rewardType", rewardType)
898
906
  result.put("rewardAmount", rewardAmount)
899
- cWebView!!.loadUrl(
907
+ cWebView?.loadUrl(
900
908
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
901
909
  )
902
910
  } catch (e: JSONException) {
@@ -930,7 +938,7 @@ class emiAdmobPlugin : CordovaPlugin() {
930
938
  put("responseInfoMediationAdapterClassName", mediationAdapterClassName)
931
939
  put("responseInfoAdapterResponses", adapterResponses)
932
940
  }
933
- cWebView!!.loadUrl(
941
+ cWebView?.loadUrl(
934
942
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load', ${errorData});"
935
943
  )
936
944
 
@@ -944,10 +952,10 @@ class emiAdmobPlugin : CordovaPlugin() {
944
952
  return true
945
953
  } else if (action == "showRewardedInterstitialAd") {
946
954
  if (mActivity != null) {
947
- mActivity!!.runOnUiThread {
955
+ mActivity?.runOnUiThread {
948
956
  if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
949
957
  isAdSkip = 1
950
- rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
958
+ rewardedInterstitialAd?.show(mActivity!!) { rewardItem: RewardItem ->
951
959
  isAdSkip = 2
952
960
  val rewardAmount = rewardItem.amount
953
961
  val rewardType = rewardItem.type
@@ -955,7 +963,7 @@ class emiAdmobPlugin : CordovaPlugin() {
955
963
  try {
956
964
  result.put("rewardType", rewardType)
957
965
  result.put("rewardAmount", rewardAmount)
958
- cWebView!!.loadUrl(
966
+ cWebView?.loadUrl(
959
967
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
960
968
  )
961
969
  } catch (e: JSONException) {
@@ -972,7 +980,7 @@ class emiAdmobPlugin : CordovaPlugin() {
972
980
  return true
973
981
  } else if (action == "showPrivacyOptionsForm") {
974
982
  if (mActivity != null) {
975
- mActivity!!.runOnUiThread {
983
+ mActivity?.runOnUiThread {
976
984
  try {
977
985
  val params: ConsentRequestParameters
978
986
  if (this.setDebugGeography) {
@@ -1005,8 +1013,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1005
1013
  it1
1006
1014
  ) { loadAndShowError: FormError? ->
1007
1015
  if (loadAndShowError != null) {
1008
- mActivity!!.runOnUiThread {
1009
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + loadAndShowError.message + "' });")
1016
+ mActivity?.runOnUiThread {
1017
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + loadAndShowError.message + "' });")
1010
1018
  }
1011
1019
  }
1012
1020
  if (isPrivacyOptionsRequired == ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED) {
@@ -1015,8 +1023,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1015
1023
  it2
1016
1024
  ) { formError: FormError? ->
1017
1025
  if (formError != null) {
1018
- mActivity!!.runOnUiThread {
1019
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show.options', { message: '" + formError.message + "' });")
1026
+ mActivity?.runOnUiThread {
1027
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show.options', { message: '" + formError.message + "' });")
1020
1028
  }
1021
1029
  }
1022
1030
  }
@@ -1026,7 +1034,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1026
1034
  }
1027
1035
  },
1028
1036
  { requestConsentError: FormError ->
1029
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + requestConsentError.message + "' });")
1037
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + requestConsentError.message + "' });")
1030
1038
  })
1031
1039
  }
1032
1040
  } catch (e: Exception) {
@@ -1037,9 +1045,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1037
1045
  return true
1038
1046
  } else if (action == "consentReset") {
1039
1047
  if (mActivity != null) {
1040
- mActivity!!.runOnUiThread {
1048
+ mActivity?.runOnUiThread {
1041
1049
  try {
1042
- consentInformation!!.reset()
1050
+ consentInformation?.reset()
1043
1051
  } catch (e: Exception) {
1044
1052
  callbackContext.error(e.toString())
1045
1053
  }
@@ -1048,11 +1056,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1048
1056
  return true
1049
1057
  } else if (action == "getIabTfc") {
1050
1058
  if (mActivity != null) {
1051
- mActivity!!.runOnUiThread {
1052
- val gdprApplies = mPreferences!!.getInt("IABTCF_gdprApplies", 0)
1053
- val purposeConsents = mPreferences!!.getString("IABTCF_PurposeConsents", "")
1054
- val vendorConsents = mPreferences!!.getString("IABTCF_VendorConsents", "")
1055
- val consentString = mPreferences!!.getString("IABTCF_TCString", "")
1059
+ mActivity?.runOnUiThread {
1060
+ val gdprApplies = mPreferences?.getInt("IABTCF_gdprApplies", 0)
1061
+ val purposeConsents = mPreferences?.getString("IABTCF_PurposeConsents", "")
1062
+ val vendorConsents = mPreferences?.getString("IABTCF_VendorConsents", "")
1063
+ val consentString = mPreferences?.getString("IABTCF_TCString", "")
1056
1064
  val userInfoJson = JSONObject()
1057
1065
  try {
1058
1066
  userInfoJson.put("IABTCF_gdprApplies", gdprApplies)
@@ -1066,10 +1074,10 @@ class emiAdmobPlugin : CordovaPlugin() {
1066
1074
  //val key = "IABTCF_TCString"
1067
1075
  getString(consentString.toString())
1068
1076
  callbackContext.success(userInfoJson)
1069
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');")
1077
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');")
1070
1078
  } catch (e: Exception) {
1071
1079
  callbackContext.error(e.toString())
1072
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');")
1080
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');")
1073
1081
  }
1074
1082
  }
1075
1083
  }
@@ -1077,7 +1085,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1077
1085
  } else if (action == "loadBannerAd") {
1078
1086
  if (mActivity != null) {
1079
1087
  val options = args.getJSONObject(0)
1080
- mActivity!!.runOnUiThread {
1088
+ mActivity?.runOnUiThread {
1081
1089
  val adUnitId = options.optString("adUnitId")
1082
1090
  val position = options.optString("position")
1083
1091
  val collapsible = options.optString("collapsible")
@@ -1102,19 +1110,19 @@ class emiAdmobPlugin : CordovaPlugin() {
1102
1110
  return true
1103
1111
  } else if (action == "showBannerAd") {
1104
1112
  if (mActivity != null) {
1105
- mActivity!!.runOnUiThread {
1113
+ mActivity?.runOnUiThread {
1106
1114
  if (isBannerPause == 0) {
1107
1115
  isShowBannerAds
1108
1116
  } else if (isBannerPause == 1) {
1109
1117
  try {
1110
- bannerView!!.visibility = View.VISIBLE
1111
- bannerView!!.resume()
1118
+ bannerView?.visibility = View.VISIBLE
1119
+ bannerView?.resume()
1112
1120
 
1113
1121
  if (isOverlapping) {
1114
1122
  bannerOverlapping()
1115
1123
  }
1116
1124
 
1117
- bannerViewLayout!!.requestFocus();
1125
+ bannerViewLayout?.requestFocus();
1118
1126
 
1119
1127
 
1120
1128
  } catch (e: Exception) {
@@ -1127,7 +1135,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1127
1135
  } else if (action == "styleBannerAd") {
1128
1136
  val options = args.getJSONObject(0)
1129
1137
  if (mActivity != null) {
1130
- mActivity!!.runOnUiThread {
1138
+ mActivity?.runOnUiThread {
1131
1139
  val screenHeight: Int
1132
1140
  val usableHeight: Int
1133
1141
 
@@ -1193,11 +1201,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1193
1201
  return true
1194
1202
  } else if (action == "hideBannerAd") {
1195
1203
  if (mActivity != null) {
1196
- mActivity!!.runOnUiThread {
1204
+ mActivity?.runOnUiThread {
1197
1205
  if (isBannerShow) {
1198
1206
  try {
1199
- bannerView!!.visibility = View.GONE
1200
- bannerView!!.pause()
1207
+ bannerView?.visibility = View.GONE
1208
+ bannerView?.pause()
1201
1209
  isBannerLoad = false
1202
1210
  isBannerPause = 1
1203
1211
  bannerOverlappingToZero()
@@ -1210,12 +1218,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1210
1218
  return true
1211
1219
  } else if (action == "removeBannerAd") {
1212
1220
  if (mActivity != null) {
1213
- mActivity!!.runOnUiThread {
1221
+ mActivity?.runOnUiThread {
1214
1222
  try {
1215
1223
  if (bannerViewLayout != null && bannerView != null) {
1216
1224
  bannerOverlappingToZero()
1217
- bannerViewLayout!!.removeView(bannerView)
1218
- bannerView!!.destroy()
1225
+ bannerViewLayout?.removeView(bannerView)
1226
+ bannerView?.destroy()
1219
1227
  bannerView = null
1220
1228
  bannerViewLayout = null
1221
1229
  isBannerLoad = false
@@ -1232,7 +1240,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1232
1240
 
1233
1241
  } else if (action == "registerWebView") {
1234
1242
  if (mActivity != null) {
1235
- mActivity!!.runOnUiThread {
1243
+ mActivity?.runOnUiThread {
1236
1244
  try {
1237
1245
  registerWebView(callbackContext)
1238
1246
  } catch (e: Exception) {
@@ -1245,11 +1253,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1245
1253
  val options = args.getJSONObject(0)
1246
1254
  if (mActivity != null) {
1247
1255
  val url = options.optString("url")
1248
- mActivity!!.runOnUiThread {
1256
+ mActivity?.runOnUiThread {
1249
1257
  try {
1250
1258
  loadUrl(url, callbackContext)
1251
1259
  } catch (e: Exception) {
1252
- PUBLIC_CALLBACKS!!.error("Error load Url: " + e.message)
1260
+ PUBLIC_CALLBACKS?.error("Error load Url: " + e.message)
1253
1261
  }
1254
1262
  }
1255
1263
 
@@ -1303,19 +1311,19 @@ class emiAdmobPlugin : CordovaPlugin() {
1303
1311
  FrameLayout.LayoutParams.MATCH_PARENT,
1304
1312
  FrameLayout.LayoutParams.MATCH_PARENT
1305
1313
  )
1306
- val decorView = mActivity!!.window.decorView as ViewGroup
1314
+ val decorView = mActivity?.window?.decorView as ViewGroup
1307
1315
  decorView.addView(bannerViewLayout, params)
1308
1316
  bannerView = AdView(mActivity!!)
1309
1317
  setBannerPosition(position)
1310
1318
  setBannerSize(size)
1311
- bannerView!!.adUnitId = adUnitId
1312
- bannerView!!.adListener = bannerAdListener
1313
- bannerView!!.loadAd(buildAdRequest())
1319
+ bannerView?.adUnitId = adUnitId
1320
+ bannerView?.adListener = bannerAdListener
1321
+ bannerView?.loadAd(buildAdRequest())
1314
1322
  } else {
1315
1323
  Log.d(TAG, "Banner view layout already exists.")
1316
1324
  }
1317
1325
  } catch (e: Exception) {
1318
- PUBLIC_CALLBACKS!!.error("Error showing banner: " + e.message)
1326
+ PUBLIC_CALLBACKS?.error("Error showing banner: " + e.message)
1319
1327
  Log.d(TAG, "Error showing banner: " + e.message)
1320
1328
  }
1321
1329
  }
@@ -1387,9 +1395,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1387
1395
  try {
1388
1396
  if (mActivity != null && bannerView != null && bannerViewLayout != null) {
1389
1397
  if (lock) {
1390
- bannerViewLayout!!.addView(bannerView)
1391
- bannerViewLayout!!.bringToFront()
1392
- bannerViewLayout!!.requestFocus();
1398
+ bannerViewLayout?.addView(bannerView)
1399
+ bannerViewLayout?.bringToFront()
1400
+ bannerViewLayout?.requestFocus();
1393
1401
  lock = false
1394
1402
  }
1395
1403
  isBannerPause = 0
@@ -1397,12 +1405,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1397
1405
  } else {
1398
1406
  val errorMessage = "Error showing banner: bannerView or bannerViewLayout is null."
1399
1407
  // Log.e("isBannerAutoShow", errorMessage)
1400
- PUBLIC_CALLBACKS!!.error(errorMessage)
1408
+ PUBLIC_CALLBACKS?.error(errorMessage)
1401
1409
  }
1402
1410
  } catch (e: Exception) {
1403
1411
  val errorMessage = "Error showing banner: " + e.message
1404
1412
  // Log.e("isBannerAutoShow", errorMessage, e)
1405
- PUBLIC_CALLBACKS!!.error(errorMessage)
1413
+ PUBLIC_CALLBACKS?.error(errorMessage)
1406
1414
  }
1407
1415
  }
1408
1416
 
@@ -1412,15 +1420,15 @@ class emiAdmobPlugin : CordovaPlugin() {
1412
1420
  if (mActivity != null && isBannerLoad && bannerView != null) {
1413
1421
  try {
1414
1422
  if (lock) {
1415
- bannerViewLayout!!.addView(bannerView)
1416
- bannerViewLayout!!.bringToFront()
1417
- bannerViewLayout!!.requestFocus();
1423
+ bannerViewLayout?.addView(bannerView)
1424
+ bannerViewLayout?.bringToFront()
1425
+ bannerViewLayout?.requestFocus();
1418
1426
  lock = false
1419
1427
  }
1420
1428
  isBannerShow = true
1421
1429
  } catch (e: Exception) {
1422
1430
  lock = true
1423
- PUBLIC_CALLBACKS!!.error(e.toString())
1431
+ PUBLIC_CALLBACKS?.error(e.toString())
1424
1432
  }
1425
1433
  }
1426
1434
  }
@@ -1461,8 +1469,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1461
1469
  bannerOverlappingToZero()
1462
1470
 
1463
1471
  if (bannerViewLayout != null && bannerView != null) {
1464
- bannerViewLayout!!.removeView(bannerView)
1465
- bannerView!!.destroy()
1472
+ bannerViewLayout?.removeView(bannerView)
1473
+ bannerView?.destroy()
1466
1474
  bannerView = null
1467
1475
  bannerViewLayout = null
1468
1476
  isBannerLoad = false
@@ -1532,7 +1540,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1532
1540
  if (bannerView!!.isCollapsible) "collapsible" else "not collapsible"
1533
1541
  )
1534
1542
 
1535
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.is.collapsible', $eventData)")
1543
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.is.collapsible', $eventData)")
1536
1544
 
1537
1545
  bannerView?.onPaidEventListener = bannerPaidAdListener
1538
1546
 
@@ -1568,24 +1576,24 @@ class emiAdmobPlugin : CordovaPlugin() {
1568
1576
 
1569
1577
  private fun bannerOverlappingToZero() {
1570
1578
  if (bannerView != null && mActivity != null && cWebView != null) {
1571
- mActivity!!.runOnUiThread {
1579
+ mActivity?.runOnUiThread {
1572
1580
  try {
1573
- val rootView = (cWebView!!.view.parent as View)
1581
+ val rootView = (cWebView?.view?.parent as View)
1574
1582
  rootView.post {
1575
1583
  // Get the total height of the parent view
1576
1584
  val totalHeight = rootView.height
1577
1585
 
1578
1586
  // Adjust WebView height to match parent height
1579
- val layoutParams = cWebView!!.view.layoutParams
1580
- layoutParams.height = totalHeight
1581
- cWebView!!.view.layoutParams = layoutParams
1587
+ val layoutParams = cWebView?.view?.layoutParams
1588
+ layoutParams?.height = totalHeight
1589
+ cWebView?.view?.layoutParams = layoutParams
1582
1590
 
1583
1591
  // Ensure no padding/margin in WebView or its parent
1584
- cWebView!!.view.setPadding(0, 0, 0, 0)
1585
- (cWebView!!.view.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
1592
+ cWebView?.view?.setPadding(0, 0, 0, 0)
1593
+ (cWebView?.view?.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
1586
1594
 
1587
1595
  // Force layout update
1588
- cWebView!!.view.requestLayout()
1596
+ cWebView?.view?.requestLayout()
1589
1597
 
1590
1598
  Log.d("BannerAdjustment", "WebView set to full height: $totalHeight")
1591
1599
  }
@@ -1601,17 +1609,17 @@ class emiAdmobPlugin : CordovaPlugin() {
1601
1609
 
1602
1610
  private fun bannerOverlapping() {
1603
1611
  if (bannerView != null && mActivity != null && cWebView != null) {
1604
- mActivity!!.runOnUiThread {
1612
+ mActivity?.runOnUiThread {
1605
1613
  try {
1606
1614
 
1607
1615
  val displayMetrics = DisplayMetrics()
1608
- mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1616
+ mActivity?.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
1609
1617
  val screenHeightInPx = displayMetrics.heightPixels
1610
1618
 
1611
1619
  val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1612
- val layoutParams = cWebView!!.view.layoutParams
1613
- layoutParams.height = webViewHeight
1614
- cWebView!!.view.layoutParams = layoutParams
1620
+ val layoutParams = cWebView?.view?.layoutParams
1621
+ layoutParams?.height = webViewHeight
1622
+ cWebView?.view?.layoutParams = layoutParams
1615
1623
 
1616
1624
  // Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1617
1625
  } catch (e: Exception) {
@@ -1649,31 +1657,31 @@ class emiAdmobPlugin : CordovaPlugin() {
1649
1657
 
1650
1658
  private fun setBannerSize(size: String?) {
1651
1659
  when (size) {
1652
- "responsive_adaptive" -> bannerView!!.setAdSize(adSize)
1653
- "anchored_adaptive" -> bannerView!!.setAdSize(
1660
+ "responsive_adaptive" -> bannerView?.setAdSize(adSize)
1661
+ "anchored_adaptive" -> bannerView?.setAdSize(
1654
1662
  AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
1655
1663
  mActivity!!, adWidth
1656
1664
  )
1657
1665
  )
1658
1666
 
1659
- "full_width_adaptive" -> bannerView!!.setAdSize(
1667
+ "full_width_adaptive" -> bannerView?.setAdSize(
1660
1668
  AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
1661
1669
  mActivity!!, adWidth
1662
1670
  )
1663
1671
  )
1664
1672
 
1665
- "in_line_adaptive" -> bannerView!!.setAdSize(
1673
+ "in_line_adaptive" -> bannerView?.setAdSize(
1666
1674
  AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(
1667
1675
  mActivity!!, adWidth
1668
1676
  )
1669
1677
  )
1670
1678
 
1671
- "banner" -> bannerView!!.setAdSize(AdSize.BANNER)
1672
- "large_banner" -> bannerView!!.setAdSize(AdSize.LARGE_BANNER)
1673
- "medium_rectangle" -> bannerView!!.setAdSize(AdSize.MEDIUM_RECTANGLE)
1674
- "full_banner" -> bannerView!!.setAdSize(AdSize.FULL_BANNER)
1675
- "leaderboard" -> bannerView!!.setAdSize(AdSize.LEADERBOARD)
1676
- "fluid" -> bannerView!!.setAdSize(AdSize.FLUID)
1679
+ "banner" -> bannerView?.setAdSize(AdSize.BANNER)
1680
+ "large_banner" -> bannerView?.setAdSize(AdSize.LARGE_BANNER)
1681
+ "medium_rectangle" -> bannerView?.setAdSize(AdSize.MEDIUM_RECTANGLE)
1682
+ "full_banner" -> bannerView?.setAdSize(AdSize.FULL_BANNER)
1683
+ "leaderboard" -> bannerView?.setAdSize(AdSize.LEADERBOARD)
1684
+ "fluid" -> bannerView?.setAdSize(AdSize.FLUID)
1677
1685
  }
1678
1686
  }
1679
1687
 
@@ -1692,7 +1700,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1692
1700
  outMetrics.density = mActivity!!.resources.displayMetrics.density
1693
1701
  } else {
1694
1702
  @Suppress("DEPRECATION")
1695
- mActivity!!.windowManager.defaultDisplay.getMetrics(outMetrics)
1703
+ mActivity?.windowManager?.defaultDisplay?.getMetrics(outMetrics)
1696
1704
  }
1697
1705
 
1698
1706
  val density = outMetrics.density
@@ -1739,15 +1747,15 @@ class emiAdmobPlugin : CordovaPlugin() {
1739
1747
  it1
1740
1748
  ) { formError: FormError? ->
1741
1749
  if (formError != null) {
1742
- mActivity!!.runOnUiThread {
1743
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + formError.message + "' });")
1750
+ mActivity?.runOnUiThread {
1751
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + formError.message + "' });")
1744
1752
  }
1745
1753
  }
1746
1754
  }
1747
1755
  }
1748
1756
  },
1749
1757
  { formError: FormError ->
1750
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from', { message: '" + formError.message + "' });")
1758
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from', { message: '" + formError.message + "' });")
1751
1759
  }
1752
1760
  )
1753
1761
  }
@@ -2053,11 +2061,11 @@ class emiAdmobPlugin : CordovaPlugin() {
2053
2061
  put("domain", adError.domain)
2054
2062
  put("cause", adError.cause?.toString() ?: "null")
2055
2063
  }
2056
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show', ${errorData});")
2064
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show', ${errorData});")
2057
2065
  }
2058
2066
 
2059
2067
  override fun onAdShowedFullScreenContent() {
2060
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.show');")
2068
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.show');")
2061
2069
  }
2062
2070
  }
2063
2071
  }
@@ -2066,7 +2074,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2066
2074
  private fun interstitialAdLoadCallback() {
2067
2075
  mInterstitialAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
2068
2076
  override fun onAdClicked() {
2069
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');")
2077
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');")
2070
2078
  }
2071
2079
 
2072
2080
  override fun onAdDismissedFullScreenContent() {
@@ -2074,7 +2082,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2074
2082
  isInterstitialLoad = false
2075
2083
  val mainView: View? = view
2076
2084
  mainView?.requestFocus()
2077
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.dismissed');")
2085
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.dismissed');")
2078
2086
  }
2079
2087
 
2080
2088
  override fun onAdFailedToShowFullScreenContent(adError: AdError) {
@@ -2086,15 +2094,15 @@ class emiAdmobPlugin : CordovaPlugin() {
2086
2094
  put("domain", adError.domain)
2087
2095
  put("cause", adError.cause?.toString() ?: "null")
2088
2096
  }
2089
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show', ${errorData});")
2097
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show', ${errorData});")
2090
2098
  }
2091
2099
 
2092
2100
  override fun onAdImpression() {
2093
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.impression');")
2101
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.impression');")
2094
2102
  }
2095
2103
 
2096
2104
  override fun onAdShowedFullScreenContent() {
2097
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.show');")
2105
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.show');")
2098
2106
  }
2099
2107
  }
2100
2108
  }
@@ -2111,7 +2119,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2111
2119
  isRewardedLoad = false
2112
2120
  val mainView: View? = view
2113
2121
  mainView?.requestFocus()
2114
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.ad.skip');")
2122
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.ad.skip');")
2115
2123
  }
2116
2124
  rewardedAd = null
2117
2125
  isRewardedLoad = false