I am using the PrintManager to print a webpage, how can my activity get a callback once printing was successfull? I am using this code:
// Get a PrintManager instance
PrintManager printManager = (PrintManager) this.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());
// Save the job object for later status checking
//mPrintJobs.add(printJob);
Create a wrapper around the PrintDocumentAdapter
received from the webView. Then you can put a hook in the onFinish().
public class PrintDocumentAdapterWrapper extends PrintDocumentAdapter{
private final PrintDocumentAdapter delegate;
public PrintDocumentAdapterWrapper(PrintDocumentAdapter adapter){
super();
this.delegate = adapter;
}
public void onFinish(){
delegate.onFinish();
//insert hook here
}
//override all other methods with a trivial implementation calling to the delegate
}
And here is how to use it in your code :
// Get a PrintManager instance
PrintManager printManager = (PrintManager) this.getSystemService(Context.PRINT_SERVICE);
// Get a print adapter instance and wrap it in my own adapter
PrintDocumentAdapter printAdapter = new PrintDocumentAdapterWrapper(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());
// Save the job object for later status checking
//mPrintJobs.add(printJob);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With