From 74ff147615994f282ba4b5c72233af7531b8273e Mon Sep 17 00:00:00 2001 From: Ann3388p Date: Thu, 21 May 2026 11:31:11 +0530 Subject: [PATCH 1/4] fix: handle edge-to-edge insets in WebViewActivity for Android 15+ --- .../url_launcher_android/CHANGELOG.md | 1 + .../plugins/urllauncher/WebViewActivity.java | 15 ++++++++++ .../urllauncher/WebViewActivityTest.java | 28 +++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) 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..583eb2a81971 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 @@ -24,6 +24,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.graphics.Insets; /* Launches WebView activity */ public class WebViewActivity extends Activity { @@ -90,6 +93,18 @@ public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); webview = new WebView(this); setContentView(webview); + 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..829e11abf29a 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); + } +} \ No newline at end of file From 9819bac9a34a6728898ef52c4aff111504753e5e Mon Sep 17 00:00:00 2001 From: Ann3388p Date: Thu, 21 May 2026 11:52:33 +0530 Subject: [PATCH 2/4] fix: address review comments - fix imports and indentation --- .../plugins/urllauncher/WebViewActivity.java | 25 ++++++++----------- .../urllauncher/WebViewActivityTest.java | 17 +++++++------ 2 files changed, 19 insertions(+), 23 deletions(-) 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 583eb2a81971..37f86d7f1281 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,12 +21,12 @@ 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; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; -import androidx.core.graphics.Insets; /* Launches WebView activity */ public class WebViewActivity extends Activity { @@ -93,18 +93,13 @@ public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); webview = new WebView(this); setContentView(webview); - ViewCompat.setOnApplyWindowInsetsListener(webview, (v, insets) -> { - Insets systemBars = insets.getInsets( - WindowInsetsCompat.Type.systemBars() - ); - v.setPadding( - systemBars.left, - systemBars.top, - systemBars.right, - systemBars.bottom - ); - return insets; -}); + 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 829e11abf29a..a76933eafb21 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 @@ -26,16 +26,17 @@ public void extractHeaders_returnsEmptyMapWhenHeadersBundleNull() { public void onCreate_webviewIsNotNull() { WebViewActivity activity = Robolectric.buildActivity( - WebViewActivity.class, - WebViewActivity.createIntent( - ApplicationProvider.getApplicationContext(), - "https://flutter.dev", - false, - false, - new Bundle())) + WebViewActivity.class, + WebViewActivity.createIntent( + ApplicationProvider.getApplicationContext(), + "https://flutter.dev", + false, + false, + new Bundle())) .create() .get(); assertNotNull(activity.webview); } -} \ No newline at end of file +} + From 3f4682d42051b0784c1cb1e3281abca060b10e37 Mon Sep 17 00:00:00 2001 From: Ann3388p Date: Thu, 21 May 2026 12:40:01 +0530 Subject: [PATCH 3/4] fix: apply google-java-format to WebViewActivityTest --- .../plugins/urllauncher/WebViewActivityTest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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 a76933eafb21..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 @@ -26,17 +26,16 @@ public void extractHeaders_returnsEmptyMapWhenHeadersBundleNull() { public void onCreate_webviewIsNotNull() { WebViewActivity activity = Robolectric.buildActivity( - WebViewActivity.class, - WebViewActivity.createIntent( - ApplicationProvider.getApplicationContext(), - "https://flutter.dev", - false, - false, - new Bundle())) + WebViewActivity.class, + WebViewActivity.createIntent( + ApplicationProvider.getApplicationContext(), + "https://flutter.dev", + false, + false, + new Bundle())) .create() .get(); assertNotNull(activity.webview); } } - From 3f011f4948954d068f21bd4abdf722544984218a Mon Sep 17 00:00:00 2001 From: Ann3388p Date: Thu, 21 May 2026 16:15:42 +0530 Subject: [PATCH 4/4] fix: add code comment for window insets listener --- .../java/io/flutter/plugins/urllauncher/WebViewActivity.java | 2 ++ 1 file changed, 2 insertions(+) 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 37f86d7f1281..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 @@ -93,6 +93,8 @@ 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) -> {