From b3b892301458750afd7b41f51a3e7b9495a1c813 Mon Sep 17 00:00:00 2001 From: Alex Dochioiu Date: Wed, 11 Oct 2023 10:45:10 +0300 Subject: [PATCH 1/5] imm crash fix --- .../webview/in_app_webview/InAppWebView.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java index 376452eb..e4c2d16f 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java @@ -1525,7 +1525,14 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie public void run() { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE); - if (containerView != null && imm != null && !imm.isAcceptingText()) { + boolean isAcceptingText = false; + try { + if (imm != null) { + isAcceptingText = imm.isAcceptingText(); + } + } catch (Exception ignored) { + } + if (containerView != null && imm != null && !isAcceptingText) { imm.hideSoftInputFromWindow( containerView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } From c059c5a50ebea78bc84af9fd88a9be6d07b92eb4 Mon Sep 17 00:00:00 2001 From: Alex Dochioiu Date: Wed, 11 Oct 2023 10:49:44 +0300 Subject: [PATCH 2/5] Added a comment --- .../webview/in_app_webview/InAppWebView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java index e4c2d16f..1cead81b 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java @@ -1528,6 +1528,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie boolean isAcceptingText = false; try { if (imm != null) { + // imm.isAcceptingText() seems to sometimes crash on some devices isAcceptingText = imm.isAcceptingText(); } } catch (Exception ignored) { From a1e86ae8d5f38bbc9b3df020b5360bd3ab3a8dbf Mon Sep 17 00:00:00 2001 From: Alex Dochioiu Date: Fri, 20 Oct 2023 12:10:49 +0300 Subject: [PATCH 3/5] * Fixed NPE --- lib/src/in_app_webview/in_app_webview_controller.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index ce252146..17da02ed 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1878,7 +1878,7 @@ class InAppWebViewController { ///- MacOS ([Official API - WKWebView.canGoBack](https://developer.apple.com/documentation/webkit/wkwebview/1414966-cangoback)) Future canGoBack() async { Map args = {}; - return await _channel?.invokeMethod('canGoBack', args); + return await _channel?.invokeMethod('canGoBack', args) ?? false; } ///Goes forward in the history of the WebView. From 2d9e21db87d8435cb78080f3b26cf423a2b65085 Mon Sep 17 00:00:00 2001 From: Alex Dochioiu Date: Fri, 3 Nov 2023 10:18:57 +0200 Subject: [PATCH 4/5] * Fixed canGoForward NPE --- lib/src/in_app_webview/in_app_webview_controller.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 17da02ed..139c29e7 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1903,7 +1903,7 @@ class InAppWebViewController { ///- MacOS ([Official API - WKWebView.canGoForward](https://developer.apple.com/documentation/webkit/wkwebview/1414962-cangoforward)) Future canGoForward() async { Map args = {}; - return await _channel?.invokeMethod('canGoForward', args); + return await _channel?.invokeMethod('canGoForward', args) ?? false; } ///Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward. From adcfdce7edefe061055a0d0b861cb7e18d71ccc8 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Fri, 10 Nov 2023 21:12:14 +0100 Subject: [PATCH 5/5] android imm.isAcceptingText() fix code refactoring --- .../webview/in_app_webview/InAppWebView.java | 22 ++++++++++--------- .../in_app_webview_controller.dart | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java index 1cead81b..40190061 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java @@ -660,7 +660,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie if (plugin == null) { return; } - + loadUrl(Util.getUrlAsset(plugin, assetFilePath)); } @@ -690,7 +690,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie public void takeScreenshot(final @Nullable Map screenshotConfiguration, final MethodChannel.Result result) { final float pixelDensity = Util.getPixelDensity(getContext()); - + mainLooperHandler.post(new Runnable() { @Override public void run() { @@ -1392,9 +1392,9 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie if (printManager != null) { PrintAttributes.Builder builder = new PrintAttributes.Builder(); - + String jobName = (getTitle() != null ? getTitle() : getUrl()) + " Document"; - + if (settings != null) { if (settings.jobName != null && !settings.jobName.isEmpty()) { jobName = settings.jobName; @@ -1445,7 +1445,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie String id = UUID.randomUUID().toString(); PrintJobController printJobController = new PrintJobController(id, job, settings, plugin); plugin.printJobManager.jobs.put(printJobController.id, printJobController); - return id; + return id; } } else { Log.e(LOG_TAG, "No PrintManager available"); @@ -1525,14 +1525,16 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie public void run() { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE); + boolean isAcceptingText = false; - try { - if (imm != null) { + if (imm != null) { + try { // imm.isAcceptingText() seems to sometimes crash on some devices isAcceptingText = imm.isAcceptingText(); + } catch (Exception ignored) { } - } catch (Exception ignored) { } + if (containerView != null && imm != null && !isAcceptingText) { imm.hideSoftInputFromWindow( containerView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); @@ -1718,7 +1720,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie public void hideContextMenu() { removeView(floatingContextMenu); floatingContextMenu = null; - + if (channelDelegate != null) channelDelegate.onHideContextMenu(); } @@ -2004,7 +2006,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie public WebViewChannelDelegate getChannelDelegate() { return channelDelegate; } - + @Override public void setChannelDelegate(@Nullable WebViewChannelDelegate channelDelegate) { this.channelDelegate = channelDelegate; diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 139c29e7..ce252146 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1878,7 +1878,7 @@ class InAppWebViewController { ///- MacOS ([Official API - WKWebView.canGoBack](https://developer.apple.com/documentation/webkit/wkwebview/1414966-cangoback)) Future canGoBack() async { Map args = {}; - return await _channel?.invokeMethod('canGoBack', args) ?? false; + return await _channel?.invokeMethod('canGoBack', args); } ///Goes forward in the history of the WebView. @@ -1903,7 +1903,7 @@ class InAppWebViewController { ///- MacOS ([Official API - WKWebView.canGoForward](https://developer.apple.com/documentation/webkit/wkwebview/1414962-cangoforward)) Future canGoForward() async { Map args = {}; - return await _channel?.invokeMethod('canGoForward', args) ?? false; + return await _channel?.invokeMethod('canGoForward', args); } ///Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.