gpt4 book ai didi

android - 如何在 webview 中浏览网页历史记录

转载 作者:行者123 更新时间:2023-11-30 03:01:06 33 4
gpt4 key购买 nike

我的应用程序中包含 WebView 。我想浏览网页历史记录,但我不知道该怎么做。请帮我。我的 Main.java 下面:

package com.abc.test;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv = (WebView)findViewById(R.id.webview);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
wv.loadUrl("http://www.google.com");

}
}

最佳答案

这是代码

public void goBackInWebView(){
WebBackForwardList history = webView.copyBackForwardList();
int index = -1;
String url = null;

while (webView.canGoBackOrForward(index)) {
if (!history.getItemAtIndex(history.getCurrentIndex() + index).getUrl().equals("about:blank")) {
webView.goBackOrForward(index);
url = history.getItemAtIndex(-index).getUrl();
Log.e("tag","first non empty" + url);
break;
}
index --;

}
// no history found that is not empty
if (url == null) {
finish();
}
}

关于android - 如何在 webview 中浏览网页历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22515991/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com