Skip to content

Commit b90ad98

Browse files
committed
fix(android): safe area handling for Android 15+
1 parent b8e0b88 commit b90ad98

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5+
import android.os.Build;
56
import android.util.DisplayMetrics;
67
import android.util.Log;
78
import android.view.Gravity;
@@ -102,21 +103,23 @@ public void showBanner(final PluginCall call) {
102103
break;
103104
}
104105

105-
// set Safe Area
106-
View rootView = activitySupplier.get().getWindow().getDecorView();
107-
rootView.setOnApplyWindowInsetsListener((v, insets) -> {
108-
int bottomInset = insets.getSystemWindowInsetBottom();
109-
int topInset = insets.getSystemWindowInsetTop();
110-
111-
if ("TOP_CENTER".equals(adOptions.position)) {
112-
mAdViewLayoutParams.setMargins(0, topInset, 0, 0);
113-
} else {
114-
mAdViewLayoutParams.setMargins(0, 0, 0, bottomInset);
115-
}
106+
// set Safe Area only for Android 15+
107+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
108+
View rootView = activitySupplier.get().getWindow().getDecorView();
109+
rootView.setOnApplyWindowInsetsListener((v, insets) -> {
110+
int bottomInset = insets.getSystemWindowInsetBottom();
111+
int topInset = insets.getSystemWindowInsetTop();
112+
113+
if ("TOP_CENTER".equals(adOptions.position)) {
114+
mAdViewLayoutParams.setMargins(0, topInset, 0, 0);
115+
} else {
116+
mAdViewLayoutParams.setMargins(0, 0, 0, bottomInset);
117+
}
116118

117-
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
118-
return insets;
119-
});
119+
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
120+
return insets;
121+
});
122+
}
120123

121124
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
122125

0 commit comments

Comments
 (0)