2

I've included a a WebView in my Android app that connects to a credit card verification service. The form loads correctly and I get errors as expected if I put in the wrong values. However, for the correct values the service redirects to another page that should show the successful verification message. Instead, I only get an "Object moved to here" message. When I click the 'here' it just goes blank. I tried overloading the WebViewClient as below thinking that the redirect may not be handling correctly but that doesn't seem to help.

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://username:password@address...");
mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.e("WebViewLog",url);
            view.loadUrl(url);

            return true;
        }
});

What can I do to fix this ?

I should add that the URL's have basic authentication. I pass this information in the URL is mWebView.loadUrl("http://username:password@address...").

LogCat is as below:

01-21 23:02:12.167: D/dalvikvm(3974): GC_CONCURRENT freed 1240K, 58% free 3061K/7175K, external 3160K/3465K, paused 1ms+2ms
01-21 23:02:17.867: D/navcache(3974): cursorInputFieldAction : No node under current cursor
01-21 23:02:17.867: D/navcache(3974): cursorInputFieldAction cursor=50e014, cursorFrame=50d828
01-21 23:02:17.867: D/navcache(3974): CachedFrame::previousInputField this=50d828, start=50e014, begin=50dfb0 end=50e208
01-21 23:02:17.867: D/navcache(3974): CachedFrame::nextInputField this=50d828, start=50e014, begin=50dfb0 end=50e208
01-21 23:02:17.867: D/navcache(3974): cursorInputFieldAction next=50e140, prev=0, action=8
01-21 23:02:17.999: V/webview(3974): OnSizeChanged: Enter 
01-21 23:02:17.999: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:20.335: W/KeyCharacterMap(3974): No keyboard for id 0
01-21 23:02:20.335: W/KeyCharacterMap(3974): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-21 23:02:20.363: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:20.878: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:21.320: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:22.164: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:22.855: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:23.183: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:23.492: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....    
01-21 23:02:23.769: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:24.531: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:24.874: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:25.187: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:25.507: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:27.210: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:27.546: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:27.812: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:28.117: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:37.542: D/navcache(3974): cursorInputFieldAction cursor=4bd634, cursorFrame=4f3160
01-21 23:02:37.542: D/navcache(3974): CachedFrame::previousInputField this=4f3160, start=4bd634,     begin=4bd5d0 end=4bd828
01-21 23:02:37.542: D/navcache(3974): CachedFrame::nextInputField this=4f3160, start=4bd634,     begin=4bd5d0 end=4bd828
01-21 23:02:37.542: D/navcache(3974): cursorInputFieldAction next=4bd760, prev=0, action=8
01-21 23:02:37.632: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:37.648: V/webview(3974): OnSizeChanged: Enter 
01-21 23:02:38.847: D/navcache(3974): cursorInputFieldAction cursor=507fd0, cursorFrame=4f3160
01-21 23:02:38.847: D/navcache(3974): CachedFrame::previousInputField this=4f3160, start=507fd0,     begin=507e40 end=508098
01-21 23:02:38.847: D/navcache(3974): CachedFrame::nextInputField this=4f3160, start=507fd0,     begin=507e40 end=508098
01-21 23:02:38.847: D/navcache(3974): cursorInputFieldAction next=508034, prev=507ea4, action=9
01-21 23:02:39.070: D/dalvikvm(3974): GC_CONCURRENT freed 1098K, 57% free 3087K/7175K, external     3171K/3465K, paused 2ms+2ms
01-21 23:02:39.109: V/webview(3974): OnSizeChanged: Enter 
01-21 23:02:39.164: V/webview(3974): Select Control Rect(101, 210 - 161, 241)
01-21 23:02:41.261: V/webview(3974): OnSizeChanged: Enter 
01-21 23:02:42.656: D/navcache(3974): cursorInputFieldAction cursor=507ff4, cursorFrame=4cb1d0
01-21 23:02:42.656: D/navcache(3974): CachedFrame::previousInputField this=4cb1d0, start=507ff4,     begin=507e00 end=508058
01-21 23:02:42.656: D/navcache(3974): CachedFrame::nextInputField this=4cb1d0, start=507ff4,     begin=507e00 end=508058
01-21 23:02:42.656: D/navcache(3974): cursorInputFieldAction next=0, prev=507f90, action=18
01-21 23:02:42.847: V/webview(3974): OnSizeChanged: Enter 
01-21 23:02:42.902: V/webview(3974): Select Control Rect(165, 210 - 242, 241)
01-21 23:02:45.308: V/webview(3974): OnSizeChanged: Enter 
01-21 23:03:12.296: D/dalvikvm(3974): GC_CONCURRENT freed 1166K, 57% free 3129K/7175K, external     3171K/3465K, paused 9ms+3ms
01-21 23:03:12.304: D/webviewglue(3974): nativeDestroy view: 0x449480

I get the Doing a super.requestRectangleOnScreen error every time I click something. Otherwise, the Log.e that I put in the WebViewClient code doesn't even show.

Update: I did the same activity on the Android browser (on a Galaxy Tab). No problems at all but I'm noting the differences here for reference. I get a username and password prompt cause I use the direct link but I also get a certificate exception which I accept because this is a BETA for testing. Also, the Android browser works using both http:// and https:// but the WebView doesn't even show the first page is I use https:// with the URL.

Saad Farooq
  • 13,172
  • 10
  • 68
  • 94
  • You need to post more information, the log about the "Object moved to here" would help. Post more code, update. – JoxTraex Jan 21 '12 at 12:19
  • How can I get the log for the "Object moved to" ? I posted the LogCat from my Android project and that doesn't seem to show anything related. – Saad Farooq Jan 21 '12 at 12:44
  • then were ar eyou seeing this? post wherever you're seeing this. – JoxTraex Jan 21 '12 at 12:46
  • I see this in the WebView after I click the verify button. I think the line in my question: "I should add that the URL's have basic authentication. I pass this information in the URL is mWebView.loadUrl("http://username:password@address...")." is critical. I don't know much about this but my hunch is that this is an authentication problem for the redirect. Just my opinion... – Saad Farooq Jan 21 '12 at 12:54
  • Call `setWebViewClient` before you attempt any calls to load the urls perhaps? – Squonk Jan 21 '12 at 13:15

3 Answers3

0

the parse() method of the Uri class to convert an URL string into an Uri object.

 public void onReceivedSslError(WebView view,
    SslErrorHandler handler, SslError error) {
 Log.e("Error", "Received SSL error"+ error.toString());
 handler.proceed();
}
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
0

public boolean shouldOverrideUrlLoading (WebView view, String url) Since: API Level 1

Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url. If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url.

This always confuses me but to explain...

When a new url is about to be loaded, this method is called. If you return true then the host application will handle the url. In other words, returning true tells the host application that it SHOULD override url loading - this can cause redirections or the stock browser to be invoked. This, as far as I can tell, is not what you want.

You should return false to show the host application that your WebView has handled it and that the host application SHOULD NOT override url loading.

Community
  • 1
  • 1
Squonk
  • 48,735
  • 19
  • 103
  • 135
0

Solved it. It was the Authentication after all. After trying all the authentication methods for WebView, I switched to SSL.

The certificate was causing a problem which I was able to bypass using the following method override in the WebViewClient.

@Override
public void onReceivedSslError(WebView view,
                SslErrorHandler handler, SslError error) {
Log.e("Error", "Received SSL error"+ error.toString());
handler.proceed();
}

Disclaimer: I'm doing this for testing as this is a beta. This would probably not be a good idea on something serious. However, there seems to be some confusion over how Android WebView works with SSL. For anyone interested, the following links may be useful: https://stackoverflow.com/a/5978391/780694 and http://r3gis.fr/blog/index.php?post/2009/11/17/Android-WebView-and-ssl-self-signed-certificates

Community
  • 1
  • 1
Saad Farooq
  • 13,172
  • 10
  • 68
  • 94