我对android开发完全陌生。最近我被要求调查一些关于我们的应用程序的 webview 加载的事情,它是由 Flutter 编写的,并使用了 flutter_webview_plugin。
在我升级flutter_webview_plugin 之后,我发现有一些变化。
而且flutter_webview_plugin里面有代码
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Map<String, Object> data = new HashMap<>();
data.put("url", url);
data.put("type", "startLoad");
FlutterWebviewPlugin.channel.invokeMethod("onState", data);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Map<String, Object> data = new HashMap<>();
data.put("url", url);
FlutterWebviewPlugin.channel.invokeMethod("onUrlChanged", data);
data.put("type", "finishLoad");
FlutterWebviewPlugin.channel.invokeMethod("onState", data);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
// returning true causes the current WebView to abort loading the URL,
// while returning false causes the WebView to continue loading the URL as usual.
String url = request.getUrl().toString();
boolean isInvalid = checkInvalidUrl(url);
Map<String, Object> data = new HashMap<>();
data.put("url", url);
data.put("type", isInvalid ? "abortLoad" : "shouldStart");
FlutterWebviewPlugin.channel.invokeMethod("onState", data);
return isInvalid;
}
我尝试使用 到处搜索shouldOverrideUrlLoading, onPageStarted,onPageFinished
,但找不到调用它们的位置。我认为它们应该被如下使用:
BrowserClient webViewClient;
webviewClient.shouldOverrideUrlLoading()
或者
webViewClient.invokeMethod('shouldOverrideUrlLoading',arg)
类似上面的东西。但我什么也找不到。