diff --git a/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java b/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java index c6291395..10f9605b 100644 --- a/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java +++ b/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Context; +import android.content.pm.PackageInfo; import android.os.Build; import android.util.DisplayMetrics; import android.util.Log; @@ -13,6 +14,7 @@ import androidx.annotation.NonNull; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.util.Supplier; +import androidx.webkit.WebViewCompat; import com.getcapacitor.JSObject; import com.getcapacitor.PluginCall; import com.getcapacitor.community.admob.helpers.AdViewIdHelper; @@ -34,6 +36,9 @@ public class BannerExecutor extends Executor { private AdView mAdView; private ViewGroup mViewGroup; + // https://issues.chromium.org/issues/40699457 + private static final int WEBVIEW_VERSION_WITH_SAFE_AREA_FIX = 140; + public BannerExecutor( Supplier contextSupplier, Supplier activitySupplier, @@ -103,8 +108,9 @@ public void showBanner(final PluginCall call) { break; } - // set Safe Area only for Android 15+ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { + // set Safe Area only for Android WebView version 140+ due to the following issue: + // https://issues.chromium.org/issues/40699457 + if (getWebViewMajorVersion() >= WEBVIEW_VERSION_WITH_SAFE_AREA_FIX) { View rootView = activitySupplier.get().getWindow().getDecorView(); rootView.setOnApplyWindowInsetsListener((v, insets) -> { int bottomInset = insets.getSystemWindowInsetBottom(); @@ -300,4 +306,18 @@ public void onAdImpression() { mViewGroup.addView(mAdViewLayout); }); } + + private Integer getWebViewMajorVersion() { + try { + PackageInfo info = WebViewCompat.getCurrentWebViewPackage(contextSupplier.get()); + if (info != null && info.versionName != null) { + String[] versionSegments = info.versionName.split("\\."); + return Integer.valueOf(versionSegments[0]); + } + } catch (Throwable ignored) { + // WebViewCompat can fail to initialize in local JVM unit tests. + } + + return 0; + } }