Ammar
Ammar

Reputation: 1821

WebViewClient.shouldOverrideUrlLoading giving invalid url

I'm setting WebView's content as;

String displayBodyText = "<a href="scheme:/user_abd/data?q=from%3A%22ammar%40mydomain.com%22#title=%40Ammar%20">Ammar</a>"
webView.loadData(displayBodyText , "text/html", "utf-8");

And set the WebViewClient as;

linkDetailWebView.setWebViewClient(new WebViewClient() {
                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            Log.d("TAG", url);
                            return true;
                        }
                    });

When clicked on the link in data, I'm getting scheme:/user_abd/data?q=from: instead of scheme:/user_abd/data?q=from%3A%22ammar%40mydomain.com%22#title=%40Ammar%20.

I'n unable to get this behavior of WebView.

Upvotes: 1

Views: 1689

Answers (2)

user4571931
user4571931

Reputation:

Try this code I checked it works for me

String displayBodyText = "<a href=\"scheme:/user_abd/data?q=from:&#34;[email protected]&#34;#title=@Ammar\">Ammar</a>";
web_view.loadData(displayBodyText , "text/html", "utf-8");

Webview client

web_view.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            String m_url = URLDecoder.decode(url);
            Log.e("TAG",m_url);

            return true;
        }
});

Upvotes: 1

Lars Nielsen
Lars Nielsen

Reputation: 150

You have to escape your invalid characters from your string:

String displayBodyText = "<a href=\"scheme:/user_abd/data?q=from%3A%22ammar%40mydomain.com%22#title=%40Ammar%20\">Ammar</a>";

You can't have double quotes in a string without escaping them: Escape double quotes in Java

Upvotes: 0

Related Questions