Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView disappears when I click on an embedded link

I've done alot of Googling on this and haven't found an answer. I have a webview as part of an overall layout with other controls. I use the webview to show formatted text (recipe descriptions with bold and italic fonts) and URLs. The URLs point to Youtube and are fully qualified (ie. http://www.youtube.com/watch?v=fyzyhuVgzRE). When I click on the link in my web view, the web view control itself disappears from the layout (leaving the rest of the controls on the page intact) and the default web browser does not launch.

It behaves as if I've set the visibility of the web view to GONE, but I do not manipulate the visibility of any of the controls on the layout.

One interesting clue in the LogCat output is an INFO level message from the OS:

MotionRecognitionManager  .unregisterListener : / listener count = 0->0,
listener=android.webkit.ZoomManager$1@41ac2fc0

Any ideas what would cause this behavior?

EDIT

Here is how I setup the webview in the onCreate() method of the activity:

webView1 = (WebView)findViewById(R.id.webView1);
webView1.getSettings().setJavaScriptEnabled(true);
webView1.getSettings().setAllowFileAccess(true);
webView1.setWebViewClient(new MyWebViewClient());

And the MyWebViewClient class:

private class MyWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url != null && url.startsWith("http://")) {
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
        } else {
            return false;
        }
    }
}

Oddly enough the shouldOverrideUrlLoading is never called.

like image 639
Kaptkaos Avatar asked Dec 22 '25 16:12

Kaptkaos


1 Answers

Well, I'm a dope. It turns out that the double quotes in the href attribute of the anchor were doubled. My system integrates with a MySQL db over the web and I have to do alot of transformation of data between MySQL/PHP and Android/SQLite. During one of these transformations I double-escaped the quotes in the href. So what should have been:

<a href="http://some_web_site">Link Text</a>

was instead rendered as:

<a href=""http://some_web_site"">Link Text</a>

In the web view the resulting URL looked fine. It was underscored properly and looked like any other URL. It is odd though that simple doubling the quotes causes the behavior. I'll see if there is a known bug like this for Android. At the very least the WebView should through some kind of exception, not simply disappear from the screen.

like image 163
Kaptkaos Avatar answered Dec 24 '25 11:12

Kaptkaos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!