机器人的WebView - 导航回URL重定向 [英] Android WebView - navigating back on URL redirection
问题描述
我对Android的WebView的问题。
I have a question on the Android webview.
假设一个URL重定向到URL B点。
Assume URL A redirects to URL B.
我当它试图打开URL一款Android应用,web视图自动重定向到网址B.。
My android application when it tries to open URL A, webview automatically redirects to URL B.
如果一个网址被重定向到一些其他的网址,我看到这两个网址都存储在web视图的历史。现在我的WebView历史由[,URL A,网址B]
If a URL is being redirected to some other url, I see both these urls are stored in webview history. Now my webview history consists of [, , URL A, URL B ]
在返回键点击的网址B.网页,web视图将尝试加载网址A,这再次重定向到URL B.我们需要双击返回键回到超越网址A
On back key click from URL B webpage, webview will try to load URL A, which again redirects to URL B. We need to double click back key to go back beyond URL A
我要如何解决这个问题?从近2小时的奋力:(
How do I solve this issue ? Struggling from the past 2 hours :(
推荐答案
我有一个同样的问题也和知道如何解决它。这就像你的。当我点击一个链接(www.new.a),它会自动重定向其他链接(mobile.new.a)。通常情况下,链接重定向两个或三个,和我的解决方案已经制定上几乎每一个重定向的链接。我希望这个答案帮助您与annyoing重定向连接。
I have a same problem too, and figured out how to solve it. It's like yours. When I click the first link(www.new.a) it automatically redirects other link(mobile.new.a). Usually the links redirect two or three, and my solution have been worked on almost every redirect links. I hope this answer help you out with annyoing redirecting links.
我终于想通了这一点。你需要一个 WebViewClient 有四个API。有shouldOverrideUrlLoading(),onPageStarted(),onPageFinished(),和doUpdateVisitedHistory()中的WebViewClient。您需要的所有的API是API 1,因此不用担心。
I finally figured out that. You need a WebViewClient with four APIs. There are shouldOverrideUrlLoading(), onPageStarted(), onPageFinished(), and doUpdateVisitedHistory() in the WebViewClient. All the APIs you need is API 1 so don't worry about.
它是这样的。您可以使用其他的功能,而不是的onkeyup()。
It goes like this. You can use other function rather than onKeyUp().
public class MyWebView extends WebView{
...
private int mRedirectedCount=0;
....
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && this.canGoBack()) {
if(mRedirectedCount>0){
while(mRedirectedCount>0){
this.goBack();
mRedirectedCount--;
}
mRedirectedCount=0; //clear
}else{
this.goBack();
}
return true;
}
private class MyWebViewClinet extends WebViewClient{
boolean mIsPageFinished=true;
...
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
.....
if(mIsPageFinished){
mRedirectedCount=0; //clear count
}
.....
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
mIsPageFinished = false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mIsPageFinished = true;
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
super.doUpdateVisitedHistory(view, url, isReload);
if(!mIsPageFinished){
mRedirectedCount++;
}
}
这篇关于机器人的WebView - 导航回URL重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!