diff --git a/packages/url_launcher/url_launcher_android/CHANGELOG.md b/packages/url_launcher/url_launcher_android/CHANGELOG.md index 5d6c25a8f7a3..728fd18be636 100644 --- a/packages/url_launcher/url_launcher_android/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_android/CHANGELOG.md @@ -1,6 +1,7 @@ ## NEXT * Updates minimum supported SDK version to Flutter 3.38/Dart 3.10. +* Fixes WebView content being obscured by system navigation bar on Android 15+ ## 6.3.30 diff --git a/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java b/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java index 5f1b1aa628e8..ba3c90868d96 100644 --- a/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java +++ b/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java @@ -21,6 +21,9 @@ import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.core.content.ContextCompat; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -90,6 +93,15 @@ public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); webview = new WebView(this); setContentView(webview); + // Apply system window insets as padding to prevent WebView content +// from being obscured by system bars (e.g. navigation bar) on Android 15+. + ViewCompat.setOnApplyWindowInsetsListener( + webview, + (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); // Get the Intent that started this activity and extract the string final Intent intent = getIntent(); final String url = intent.getStringExtra(URL_EXTRA); diff --git a/packages/url_launcher/url_launcher_android/android/src/test/java/io/flutter/plugins/urllauncher/WebViewActivityTest.java b/packages/url_launcher/url_launcher_android/android/src/test/java/io/flutter/plugins/urllauncher/WebViewActivityTest.java index 9541608b764b..c3db6ed7dd8f 100644 --- a/packages/url_launcher/url_launcher_android/android/src/test/java/io/flutter/plugins/urllauncher/WebViewActivityTest.java +++ b/packages/url_launcher/url_launcher_android/android/src/test/java/io/flutter/plugins/urllauncher/WebViewActivityTest.java @@ -1,17 +1,41 @@ // Copyright 2013 The Flutter Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - package io.flutter.plugins.urllauncher; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import android.os.Bundle; +import androidx.test.core.app.ApplicationProvider; import java.util.Collections; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +@RunWith(RobolectricTestRunner.class) public class WebViewActivityTest { + @Test public void extractHeaders_returnsEmptyMapWhenHeadersBundleNull() { assertEquals(WebViewActivity.extractHeaders(null), Collections.emptyMap()); } + + @Test + public void onCreate_webviewIsNotNull() { + WebViewActivity activity = + Robolectric.buildActivity( + WebViewActivity.class, + WebViewActivity.createIntent( + ApplicationProvider.getApplicationContext(), + "https://flutter.dev", + false, + false, + new Bundle())) + .create() + .get(); + + assertNotNull(activity.webview); + } }