From 1359ecb6386d1d49dc265897234193c071d87a33 Mon Sep 17 00:00:00 2001 From: hardy716 Date: Thu, 18 May 2023 15:29:06 +0900 Subject: [PATCH] fix:Replace deprecated setAppCacheEnabled with setCacheMode --- .../WebviewManager.java | 31 +++++++------- .../plugins/GeneratedPluginRegistrant.java | 40 +++++++------------ 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java index e19b2a08..c5af5c9b 100644 --- a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java +++ b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java @@ -68,9 +68,9 @@ public boolean handleResult(int requestCode, int resultCode, Intent intent) { Uri[] results = null; if (resultCode == Activity.RESULT_OK) { if (fileUri != null && getFileSize(fileUri) > 0) { - results = new Uri[]{fileUri}; + results = new Uri[] { fileUri }; } else if (videoUri != null && getFileSize(videoUri) > 0) { - results = new Uri[]{videoUri}; + results = new Uri[] { videoUri }; } else if (intent != null) { results = getSelectedFiles(intent); } @@ -103,7 +103,7 @@ private Uri[] getSelectedFiles(Intent data) { if (data.getData() != null) { String dataString = data.getDataString(); if (dataString != null) { - return new Uri[]{Uri.parse(dataString)}; + return new Uri[] { Uri.parse(dataString) }; } } // we have multiple files selected @@ -136,9 +136,9 @@ private Uri[] getSelectedFiles(Intent data) { webViewClient = new BrowserClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { - if (ignoreSSLErrors){ + if (ignoreSSLErrors) { handler.proceed(); - }else { + } else { super.onReceivedSslError(view, handler, error); } } @@ -175,8 +175,8 @@ public void onScroll(int x, int y, int oldx, int oldy) { webView.setWebViewClient(webViewClient); webView.setWebChromeClient(new WebChromeClient() { - //The undocumented magic method override - //Eclipse will swear at you if you try to put @Override here + // The undocumented magic method override + // Eclipse will swear at you if you try to put @Override here // For Android 3.0+ public void openFileChooser(ValueCallback uploadMsg) { @@ -199,7 +199,7 @@ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { FILECHOOSER_RESULTCODE); } - //For Android 4.1 + // For Android 4.1 public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); @@ -209,7 +209,7 @@ public void openFileChooser(ValueCallback uploadMsg, String acceptType, Str } - //For Android 5.0+ + // For Android 5.0+ public boolean onShowFileChooser( WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { @@ -253,7 +253,6 @@ public boolean onShowFileChooser( return true; } - @Override public void onProgressChanged(WebView view, int progress) { Map args = new HashMap<>(); @@ -355,7 +354,8 @@ private void clearCache() { private void registerJavaScriptChannelNames(List channelNames) { for (String channelName : channelNames) { webView.addJavascriptInterface( - new JavaScriptChannel(FlutterWebviewPlugin.channel, channelName, platformThreadHandler), channelName); + new JavaScriptChannel(FlutterWebviewPlugin.channel, channelName, platformThreadHandler), + channelName); } } @@ -380,8 +380,7 @@ void openUrl( String invalidUrlRegex, boolean geolocationEnabled, boolean debuggingEnabled, - boolean ignoreSSLErrors - ) { + boolean ignoreSSLErrors) { webView.getSettings().setJavaScriptEnabled(withJavascript); webView.getSettings().setBuiltInZoomControls(withZoom); webView.getSettings().setSupportZoom(withZoom); @@ -392,7 +391,7 @@ void openUrl( webView.getSettings().setSupportMultipleWindows(supportMultipleWindows); - webView.getSettings().setAppCacheEnabled(appCacheEnabled); + webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); webView.getSettings().setAllowFileAccessFromFileURLs(allowFileURLs); webView.getSettings().setAllowUniversalAccessFromFileURLs(allowFileURLs); @@ -407,7 +406,7 @@ void openUrl( if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webView.setWebContentsDebuggingEnabled(debuggingEnabled); } - //ignore SSL errors + // ignore SSL errors this.ignoreSSLErrors = ignoreSSLErrors; webViewClient.updateInvalidUrlRegex(invalidUrlRegex); @@ -533,7 +532,7 @@ boolean canGoForward() { /** * Clears cache */ - void cleanCache(){ + void cleanCache() { webView.clearCache(true); } diff --git a/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java index ac75cf38..cf02bf33 100644 --- a/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java +++ b/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java @@ -1,35 +1,25 @@ package io.flutter.plugins; -// import io.flutter.plugin.common.PluginRegistry; -import androidx.annotation.NonNull; -import io.flutter.embedding.engine.FlutterEngine; -import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry; +import io.flutter.plugin.common.PluginRegistry; import com.flutter_webview_plugin.FlutterWebviewPlugin; /** * Generated file. Do not edit. */ -// public final class GeneratedPluginRegistrant { -// public static void registerWith(PluginRegistry registry) { -// if (alreadyRegisteredWith(registry)) { -// return; -// } -// FlutterWebviewPlugin.registerWith(registry.registrarFor("com.flutter_webview_plugin.FlutterWebviewPlugin")); -// } - -// private static boolean alreadyRegisteredWith(PluginRegistry registry) { -// final String key = GeneratedPluginRegistrant.class.getCanonicalName(); -// if (registry.hasPlugin(key)) { -// return true; -// } -// registry.registrarFor(key); -// return false; -// } -// } - public final class GeneratedPluginRegistrant { - public static void registerWith(@NonNull FlutterEngine flutterEngine) { - ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine); - FlutterWebviewPlugin.registerWith(shimPluginRegistry.registrarFor("com.flutter_webview_plugin.FlutterWebviewPlugin")); + public static void registerWith(PluginRegistry registry) { + if (alreadyRegisteredWith(registry)) { + return; + } + FlutterWebviewPlugin.registerWith(registry.registrarFor("com.flutter_webview_plugin.FlutterWebviewPlugin")); + } + + private static boolean alreadyRegisteredWith(PluginRegistry registry) { + final String key = GeneratedPluginRegistrant.class.getCanonicalName(); + if (registry.hasPlugin(key)) { + return true; + } + registry.registrarFor(key); + return false; } }