Android WebView captures the information in the clicked URL

Source: Internet
Author: User
<span id="Label3"></p><p><p>Project requirements, Click on the search keyword in webview, load other Web pages, you need to display the keywords in a text input box in real time</p></p><p><p>In fact, This click is within the webview, and does not jump out of this webview,activity and does not experience any life cycle. Seemingly unable to capture</p></p><p><p>In fact, it is simple to rewrite the <span style="color: #000000;">shouldoverrideurlloading () to get the URL of the various click Events. Parse its argument list to see if there are</span> any</p></p><p><p><span style="color: #000000;">Keys keyword, to get its value, parse, display on it.</span></p></p><p><p></p></p><p><p></p></p><pre><pre><span style="color: #000000;"><span style="color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px;"><span style="color: #000000;">Shouldoverrideurlloading () method<br></span>Returns true to indicate that clicking on a link in a Web page or jumping in the current WebView<br>return false to jump to another browser</span></span></pre></pre><p><p></p></p><p><p></p></p><pre><pre><br><span style="color: #0000ff; font-size: 15px;"><span style="text-decoration: underline;"><em><span style="color: #ff6600; text-decoration: underline;"><span style="color: #ff6600; text-decoration: underline;">URL parameter Resolution Class</span></span></em></span></span></pre></pre><p><p></p></p><p><p></p></p><pre><span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>Mywebviewclient<span style="color: #0000ff;"><span style="color: #0000ff;">extends</span></span><span style="color: #000000;"><span style="color: #000000;">webviewclient {@Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">Boolean</span></span><span style="color: #000000;"><span style="color: #000000;">shouldoverrideurlloading (WebView view, String Url) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(url.startswith ("intent://"<span style="color: #000000;"><span style="color: #000000;">)){ </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span><span style="color: #000000;"><span style="color: #000000;">; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. shouldoverrideurlloading (view, url); </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(textutils.isempty (url))</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span><span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">the <span style="color: #008000;">Following is used to: add hint to the top edittext when you click another keyword search</span> in the page</span>DEBUGUTIL.D ("myc", "url =" +<span style="color: #000000;"><span style="color: #000000;">url);<br>Map</span></span><string, string> maprequest = Urlutil.getrequestparammap (url);<span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(maprequest!=<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>&& maprequest.size ()!=0<span style="color: #000000;"><span style="color: #000000;">) {String KeyWord</span></span>= Maprequest.get ("keys");<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Get keyword field</span></span>DEBUGUTIL.D ("myc", "keyWord =" +<span style="color: #000000;"><span style="color: #000000;">keyWord); </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(!<span style="color: #000000;"><span style="color: #000000;">Textutils.isempty (KEYWORD)) { </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Try</span></span><span style="color: #000000;"><span style="color: #000000;">{String Result</span></span>= Urldecoder.decode (keyWord, "UTF-8");<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">use Android's Urldecoder to parse into Chinese</span></span><span style="color: #000000;"><span style="color: #000000;">Setkeyword (result); } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Catch</span></span><span style="color: #000000;"><span style="color: #000000;">(unsupportedencodingexception E) {e.printstacktrace (); } } } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span><span style="color: #000000;"><span style="color: #000000;">; } @Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onpagestarted (WebView view, String url, Bitmap Favicon) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. onpagestarted (view, url, favicon); } @Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onpagefinished (WebView view, String Url) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. onpagefinished (view, url); } @Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>Onreceivederror (WebView view,<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span><span style="color: #000000;"><span style="color: #000000;">errorCode, string description, string Failingurl) { </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. Onreceivederror (view, errorCode, description, failingurl); } }</span></span></pre><p><p></p></p><p><p>Android WebView captures the information in the clicked URL</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.