I get a warning when building my android project that "createPrintDocumentAdapter" has been deprecated. It is a method on WebView.
I have been looking but have been unable to find what the intended replacement is. Can anyone shed some light on this?
Thanks, Jason
Per the Javadoc for createPrintDocumentAdapter():
This method was deprecated in API level 21.
Use createPrintDocumentAdapter(String) which requires user to provide a print document name.
Therefore if you need to support < API 21, continue to use the current method, but on API 21+ devices, use createPrintDocumentAdapter(String)
Based on the accepted answer and the official example:
@SuppressWarnings("deprecation")
private static void createWebPrintJob(Context context, WebView webView) {
// Get a PrintManager instance
PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
String jobName = context.getString(R.string.app_name) + " Document";
// Get a print adapter instance
PrintDocumentAdapter printAdapter;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
printAdapter = webView.createPrintDocumentAdapter(jobName);
}
else {
printAdapter = webView.createPrintDocumentAdapter();
}
// Create a print job with name and adapter instance
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