简体   繁体   中英

how android use BlueTooth printer print the WebView content

how to print the HTML using a bluetooth printer with android?Can I print the String="< html > < body >You scored 192 points." into html page?

There's a quick how-to on the Android Developer site about printing the contents of a WebView:

from https://developer.android.com/training/printing/html-docs.html

// Get a PrintManager instance
PrintManager printManager = (PrintManager) getActivity()
        .getSystemService(Context.PRINT_SERVICE);

// Get a print adapter instance
PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();

// Create a print job with name and adapter instance
String jobName = getString(R.string.app_name) + " Document";
PrintJob printJob = printManager.print(jobName, printAdapter,
        new PrintAttributes.Builder().build());

You don't even have to display the WebView first - in fact they recommend that you use a dedicated invisible WebView for printing.

In order to print to a Bluetooth printer though, you'll need to have the print service app for that printer installed, or use a manufacturer-specific SDK - either of which might not exist :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM