Reputation: 35956
I have used webview
with the reference http://developer.android.com/guide/webapps/debugging.html
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebChromeClient(new WebChromeClient() {
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d("MyApplication", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.d("MyApplication", message + " -- From line "
+ lineNumber + " of "
+ sourceID);
}
});
but still m not get log Logcat
Please help me out
Upvotes: 4
Views: 5364
Reputation: 1531
It appears some devices (HTC Desire and some others) with specific OS (mine had 2.3.3) do not display messages in Logcat window and it seems console.log does not work for them. I found a nice workaround using JavaScript Interface to overcome the issue: Android Console via JS interface
Upvotes: 3
Reputation: 2534
In my case (I have Samsung Note 4 running Android 6.0), onConsoleMessage
is called only if I set
myWebView.setWebContentsDebuggingEnabled(true);
and when I open the Chrome remote device debugger to inspect the webview. But obviously this is not quite helpful since I can already see the console output on the debugger window.
Upvotes: 1