如何在Android Studio(LogCat)中删除铬日志

时间:2019-04-24 04:49:18

标签: android cordova

当我打开webview Cordova(处于释放模式的应用程序)时,logcat显示以下日志I / chromium:[INFO:CONSOLE(1)]源http:// .....

如何在Android Studio(LogCat)中将这些日志删除到我的应用程序“ I / chromium:[INFO:CONSOLE(1)]”中?

2 个答案:

答案 0 :(得分:0)

有可能。 Using Console APIs in WebView

只需为您的WebView覆盖WebViewClient:

val myWebView: WebView = findViewById(R.id.webview)
myWebView.webChromeClient = object : WebChromeClient() {

override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
    consoleMessage?.apply {
        Log.d("MyApplication", "${message()} -- From line ${lineNumber()} of ${sourceId()}")
    }
    return true
    }
}

答案 1 :(得分:0)

@Volodymyr为我工作。只需在WebChromeClient(reference)上覆盖onConsoleMessage:

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Log.d(TAG, "onConsoleMessage: "+ consoleMessage.message());
            return true;
        }
    });