Java Android WebView canGoBack始终返回false
重现问题的步骤:Java Android WebView canGoBack始终返回false,java,android,google-chrome,webview,Java,Android,Google Chrome,Webview,重现问题的步骤: 创建一个包含WebView的片段 在WebView中深入浏览几个站点,构建历史记录 尝试使用webview.canGoBack()函数 注意,它总是返回false 这是一种新的行为,因为WebView以前确实返回true 新版本的WebView似乎破坏了这一功能 这是我的密码: class MyWebViewClient extends WebViewClient { // Loads all hyperlinks in the existing WebView
class MyWebViewClient extends WebViewClient {
// Loads all hyperlinks in the existing WebView
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Protection against getActivity() returning null object reference
if (!isAdded()) return true;
// Allow WebView to load url
Uri uri = Uri.parse(url);
// Google Maps
if (url.contains("maps.google")) {
Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(mapIntent);
}
return true;
}
// Telephone
else if (url.contains("tel:")) {
String phoneNumber = url.substring(4);
Utils.dialPhone(getActivity(), phoneNumber);
return true;
}
// Redirect
return false;
}
}
下面是我使用goBack API的地方:
public boolean canWebViewGoBack() {
if (mWebView != null) {
if (mWebView.canGoBack()) {
return true;
}
}
return false;
}
public void webViewGoBack() {
if (mWebView != null) {
if (mWebView.canGoBack()) {
mWebView.goBack();
}
}
}
这里
讨论问题和可能的解决方案最新Chrome发布后,WebView canGoBack功能再次发挥作用:
64.0.3282.137或者它是一个网站……是的,你说得对,因为新版本的WebView似乎破坏了这一功能。这里也一样。这个链接中唯一的解决方案是等到下一个Chrome版本(65)。