I have stripped down most of the elements from my initial code to demonstrate how it is currently functioning. I've successfully implemented a feature that fetches the webview title, but now I am looking to expand it to showcase more of the HTML content or source code. The purpose behind this enhancement is to enable me to print a receipt on a compact thermal printer.
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl("http://www.google.co.uk");
--------------------------------------------------
btnPrint.setOnClickListener(new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public void onClick(View v) {
try {
printData();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
--------------------------------------------------
@RequiresApi(api = Build.VERSION_CODES.O_MR1)
void printData() throws IOException {
try {
String msg = webview.getTitle();
msg+="\n";
outputStream.write(msg.getBytes());
lblPrinterName.setText("Printing Text...");
} catch (Exception ex){
ex.printStackTrace();
}
}