Error calculating screen insets on Android 14 on pre-release version
Describe the bug This issue happens on the 7.1.0-1 pre-release To reproduce you need to be in Android 14. There's an incorrect calculation of the system screen insets. See the pictures attached. ¿Maybe the plugin changes the display mode of the app?
- Create an emulator with Android 14
- Create a banner ad on TOP_CENTER or BOTTOM_CENTER with margin: 0
- See how the banner is incorrectly placed. (seems that the offsets are duplicated)
Expected behavior The expected behavior is what happens on Androd 15 and above, where the insets are correct.
Screenshots
https://github.com/user-attachments/assets/ccef0a06-d046-416f-911a-934d4a430de7
Smartphone (please complete the following information):
- Device: Emulator Medium Phone Android Studio
- OS: Android 14
- Browser Chrome 137
Additional context Add any other context about the problem here.
I think is related with https://github.com/capacitor-community/admob/issues/363. Are you using SDK 35 in your project?
It seems the showBanner method needs to be refactored to add the correct margins with the safe area. This commit https://github.com/capacitor-community/admob/commit/fa4c1b593574d540c90659e83cb0f2a15e3a14d4 also introduced a new bug: the banner isn't centered on the screen. @rdlabo
Sorry for the delay. I'd like you to check if it's been resolved in v7.2.0, which we released today. Thanks!
@rdlabo I'm using Android 36.1 with the plugin on 7.2.0 and the margin doesn't work, it doesn't change position no matter what number I use.
I also face same problem using version 7.2.0 on emulator (android 15) (API 35) on out android versions there is no problem. so i downgraded this plugin to 7.0.3 and this fixed the problem.
update 1: v7.2.0 is also working if we comment this part of code in BannerExecutor.java:
/*
// set Safe Area only for Android 15+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
View rootView = activitySupplier.get().getWindow().getDecorView();
rootView.setOnApplyWindowInsetsListener((v, insets) -> {
int bottomInset = insets.getSystemWindowInsetBottom();
int topInset = insets.getSystemWindowInsetTop();
if ("TOP_CENTER".equals(adOptions.position)) {
mAdViewLayoutParams.setMargins(0, topInset, 0, 0);
} else {
mAdViewLayoutParams.setMargins(0, 0, 0, bottomInset);
}
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
return insets;
});
}
*/
I also face same problem using version 7.2.0 on emulator (android 15) (API 35) on out android versions there is no problem. so i downgraded this plugin to 7.0.3 and this fixed the problem.
update 1: v7.2.0 is also working if we comment this part of code in BannerExecutor.java:
/* // set Safe Area only for Android 15+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { View rootView = activitySupplier.get().getWindow().getDecorView(); rootView.setOnApplyWindowInsetsListener((v, insets) -> { int bottomInset = insets.getSystemWindowInsetBottom(); int topInset = insets.getSystemWindowInsetTop(); if ("TOP_CENTER".equals(adOptions.position)) { mAdViewLayoutParams.setMargins(0, topInset, 0, 0); } else { mAdViewLayoutParams.setMargins(0, 0, 0, bottomInset); } mAdViewLayout.setLayoutParams(mAdViewLayoutParams); return insets; }); } */
If I disable edge-to-edge in Android 15, the code above creates a design bug, adding a black bar at the bottom.
Try to disable edge-to-edge:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme for API 35 (Android 15) -->
<!-- Opt-out of edge-to-edge enforcement (only works on API 35, removed in API 36) -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Opt-out of edge-to-edge (Android 15 only) -->
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
<!-- Opaque system bars -->
<item name="android:statusBarColor">@color/colorPrimary</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:background">@null</item>
<!-- Opt-out of edge-to-edge (Android 15 only) -->
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
<!-- Opaque system bars -->
<item name="android:statusBarColor">@color/colorPrimary</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
<item name="android:background">@drawable/splash</item>
<!-- Opt-out of edge-to-edge (Android 15 only) -->
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
<item name="android:statusBarColor">@color/colorPrimary</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
</style>
</resources>