private class SampleWebChromeClient extends WebChromeClient {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Log.d("SampleActivity", consoleMessage.message() + " -- From line "
+ consoleMessage.lineNumber() + " of "
+ consoleMessage.sourceId() );
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message,
JsResult result) {
Log.d("SampleActivity", message);
//new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
result.confirm();
return true;
}
}
For KitKat > using the below code and you can debug inside the web view. For more details refer here.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); }