Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Logcat is not working for JS console.log()

My app is a combination of Android native, html5. Till last week I'm able to see the log messages from native code and javascript code running inside th WebView. But suddenly Logcat is not showing the console messages from javascript, though it is showing Log messages from my native code. Any ideas?

Thanks in advance. Venkat

like image 366
Venkat Papana Avatar asked Jul 07 '12 08:07

Venkat Papana


1 Answers

You can try adding a console message handler to your WebView by creating your custom WebChromeClient:

class MyWebChromeClient extends WebChromeClient
{
    @Override
    public boolean onConsoleMessage(ConsoleMessage cm)
    {
        Log.d("CONTENT", String.format("%s @ %d: %s", 
                    cm.message(), cm.lineNumber(), cm.sourceId()));
        return true;
    }
}

And then attach it:

someWebView.setWebChromeClient(new MyWebChromeClient());
like image 119
3k- Avatar answered Sep 28 '22 05:09

3k-