I would prefer to get the HTML code of the webpage that needs to be loaded into the webView , webView it with a regular expression and display only the HTML code that I want, and let the webpage still think that it is loaded all.
Is there a way to do this in WebViewClient.onLoadResource() or similar methods?
EDIT: I tried this:
class MyJavaScriptInterface { @SuppressWarnings("unused") public void showHTML(String html, Context context) { new AlertDialog.Builder(context) .setTitle("HTML") .setMessage(html) .setPositiveButton(android.R.string.ok, null) .setCancelable(false) .create(); pageHTML = html; } } @Override public void customizeWebView(final ServiceCommunicableActivity activity, final WebView webview, final SearchResult mRom) { mRom.setFileSize(getFileSize(mRom.getURLSuffix())); webview.getSettings().setJavaScriptEnabled(true); MyJavaScriptInterface interfaceA = new MyJavaScriptInterface(); webview.addJavascriptInterface(interfaceA, "HTMLOUT"); WebViewClient anchorWebViewClient = new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { webview.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');"); Pattern pattern = Pattern.compile("<h2>Winning Sc.+</h2></div>(.+)<br>", Pattern.DOTALL); Matcher matcher = pattern.matcher(pageHTML); matcher.find();
The interface is never called
android html webview
Aymon Fournier Aug 13 2018-10-18 18:49
source share