[WebView Learning Five]: debugging Web Apps

Source: Internet
Author: User

The previous one we studied ([WebView learning four]: migrating to the Android4.4 version of WebView), today we will continue to learn.

(blog address: http://blog.csdn.net/developer_jiangqq), reproduced please specify.

Author:hmjiangqq

Email:[email protected]

If you are Android4.4 or a higher version to test your Web Application (application) , you can use the Chrome Developer tool to remotely debug your Web page, which also supports Android's low version. For more information, see :remotedebugging on Android.

          If you don't haveAndroid4.4or a later device, then you can use the console JavaScriptAPIsat LoGCatdebug JavaScript by printing the log messages in the If you are familiar with usingFirebugor WebInspector, then you may also be familiar with using the console(Console,For example: Console.log ()). AndroidWebkitThe framework also supports many of the same works.APIs. When we debugAndroidwhen the browser or our own webview, we can get the log message from the Web page. This article mainly explains how to use the console APIs for debugging.

( a ) in android Span lang= "ZH-CN" style= "Font-family:simsun" > browser using console a pis (Using the Console APIs in the android  browser)

          console method ( use dom objects Window.console) log The cat :

console.log ("HelloWorld");

Then in the logCat will print out the log information :

console:helloworldhttp://www.example.com/hello.html :

          android The version of the system goes. On Android 2.1 " browswer " 1.6 below, the Android browser information will be provided with the "WebCore"

AndroidWebKit Framework does not implement all console information APIs for other desktop browsers Functionality , but you can use some basic logging methods :

<span style= "FONT-SIZE:18PX;" >1.console.log (String) 2.console.info (String) 3.console.warn (String)        4.console.error (String) </span>

There are other console methods that may not be as effective as other Web browsers.

( two ) in the WebView using the console in APIs (Using the Console APIs in WebView)

        the console we introduced aboveAPIsin theWebViewalso notify support for debugging. If your device is running on Android2.1the above version, then you have to providewebchromeclientclass and implementonconsolemessage ()method to print the log to the console.then you useSetwebchromeClient()The Webchromeclient method binds the bindings to the webview you have.

        For example:toAndroidAPI7version,ImplementOnconsolemessage (String, int,string)Method:

<span style= "FONT-SIZE:18PX;"  >webview Mywebview = (WebView) Findviewbyid (R.id.webview); Mywebview.setwebchromeclient (new Webchromeclient () { public void Onconsolemessage (string message, int linenumber, string sourceid) {log.d ("MyApplication", Message + "--F  Rom Line "+ linenumber +" of "+ SourceID); }});</span>

of course, if your api The lowest version is 8 onconsole mes sae ( Con colemessage) Method For example :

<span Style= "FONT-SIZE:18PX;" >webview Mywebview = (WebView) Findviewbyid (R.id.webview); Mywebview.setwebchromeclient (new Webchromeclient () {   Public boolean onconsolemessage (consolemessage cm) {    LOG.D ("MyApplication", cm.message () + "– from L INE                          + cm.linenumber () + "of" & nbsp                        + Cm.sourceid ());    return true; }}); </span> 

    Consol emanager messagelevel , You can use messagelevel ()

      Whether you use oncon solemessage (string,int,string) or Onconsolem essage (consolemanager) at the appropriate place. onconsoldemessage () method so that you can make an error. For example, the above code, the printed log is as follows :

HelloWorld- from line to http://www.example.com/hello.html




[WebView Learning Five]: debugging Web Apps

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.