Output log information via JS code
JS Code
JS Code: Console.log ("Hello World"); Log info: Console:hello World http://www.example.com/hello.html:82
Implement the Onconsolemesaage () callback method in webchromeclient to print information in Logcat
Java code
1 WebView mywebview = (WebView) Findviewbyid (R.id.webview); 2 mywebview.setwebchromeclient (new Webchromeclient () { 3 public void onconsolemessage (String message, int linenumber, String SourceID) { 4 log.d ("MyApplication", "Message +"--From line "5 + linenumber + "of" 6 + SourceID); 7 } });
And
Java code
1WebView Mywebview =(WebView) Findviewbyid (R.id.webview); 2Mywebview.setwebchromeclient (Newwebchromeclient () {3 Public Booleanonconsolemessage (consolemessage cm) {4LOG.D ("MyApplication", cm.message () + "-From line"5+ cm.linenumber () + "of"6+Cm.sourceid ()); 7 return true; 8 } 9});
*consolemessage also includes a messagelevel that represents the console delivery information type. You can use Messagelevel () to query the information level to determine the severity of the information, and then use the appropriate log method or take other appropriate actions.
Using HTML5 to develop Android (3)---debugging in Android