本文整理汇总了Java中android.webkit.WebView.createPrintDocumentAdapter方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.createPrintDocumentAdapter方法的具体用法?Java WebView.createPrintDocumentAdapter怎么用?Java WebView.createPrintDocumentAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebView
的用法示例。
在下文中一共展示了WebView.createPrintDocumentAdapter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printOrCreatePdfFromWebview
import android.webkit.WebView; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@SuppressWarnings("deprecation")
public PrintJob printOrCreatePdfFromWebview(WebView webview, String jobName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Context c = webview.getContext();
PrintDocumentAdapter printAdapter;
PrintManager printManager = (PrintManager) c.getSystemService(Context.PRINT_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
printAdapter = webview.createPrintDocumentAdapter(jobName);
} else {
printAdapter = webview.createPrintDocumentAdapter();
}
if (printManager != null) {
return printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
}
} else {
Log.e(getClass().getName(), "ERROR: Method called on too low Android API version");
}
return null;
}
示例2: createWebPrintJob
import android.webkit.WebView; //导入方法依赖的package包/类
private void createWebPrintJob(WebView webView) {
// 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());
}