本文整理汇总了Java中android.print.PrintJob类的典型用法代码示例。如果您正苦于以下问题:Java PrintJob类的具体用法?Java PrintJob怎么用?Java PrintJob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrintJob类属于android.print包,在下文中一共展示了PrintJob类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printOrCreatePdfFromWebview
import android.print.PrintJob; //导入依赖的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: printWebView
import android.print.PrintJob; //导入依赖的package包/类
/**
* Print the current web site
*/
@RequiresApi(19)
public void printWebView(@Nullable PrintListener listener) {
PrintManager printManager = (PrintManager) getContext().getSystemService(Context.PRINT_SERVICE);
PrintDocumentAdapter printAdapter = createPrintDocumentAdapter();
PrintAttributes.Builder builder = new PrintAttributes.Builder();
builder.setMediaSize(PrintAttributes.MediaSize.ISO_A4);
PrintJob printJob = printManager.print(getTitle(), printAdapter, builder.build());
if (listener!=null) {
if(printJob.isCompleted()){
listener.onSuccess();
} else {
listener.onFailed();
}
}
}
示例3: createWebPrintJob
import android.print.PrintJob; //导入依赖的package包/类
public void createWebPrintJob(WebView webView) {
// Get a PrintManager instance
PrintManager printManager = (PrintManager) mContext
.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";
String jobName = "QuickFoodsBill";
PrintJob printJob = printManager.print(jobName, printAdapter,
new PrintAttributes.Builder().build());
// Save the job object for later status checking
mPrintJobs.add(printJob);
}
示例4: createWebPrintJob
import android.print.PrintJob; //导入依赖的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());
}
示例5: dumpJobStatesForDebug
import android.print.PrintJob; //导入依赖的package包/类
@RemovableInRelease
private void dumpJobStatesForDebug() {
List<PrintJob> printJobs = mPrintManager.getPrintJobs();
String[] states = new String[printJobs.size()];
for (int i = 0; i < printJobs.size(); i++) {
String stateString;
switch (printJobs.get(i).getInfo().getState()) {
case PrintJobInfo.STATE_CREATED:
stateString = "STATE_CREATED";
break;
case PrintJobInfo.STATE_QUEUED:
stateString = "STATE_QUEUED";
break;
case PrintJobInfo.STATE_STARTED:
stateString = "STATE_STARTED";
break;
case PrintJobInfo.STATE_BLOCKED:
stateString = "STATE_BLOCKED";
break;
case PrintJobInfo.STATE_FAILED:
stateString = "STATE_FAILED";
break;
case PrintJobInfo.STATE_COMPLETED:
stateString = "STATE_COMPLETED";
break;
case PrintJobInfo.STATE_CANCELED:
stateString = "STATE_CANCELED";
break;
default:
stateString = "STATE_UNKNOWN";
break;
}
states[i] = stateString;
}
Log.v(TAG, "Initiating new print with states in queue: {%s}", TextUtils.join(", ", states));
}
示例6: printNote
import android.print.PrintJob; //导入依赖的package包/类
private void printNote() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
PrintManager printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE);
String jobName = getString(R.string.app_name) + " Document";
PrintDocumentAdapter printAdapter = editor.createPrintDocumentAdapter();
PrintJob printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
}
}
示例7: printDocument
import android.print.PrintJob; //导入依赖的package包/类
void printDocument(WebView webView, String title)
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
PrintManager printManager = (PrintManager) mContext.getSystemService(Context.PRINT_SERVICE);
//noinspection deprecation
PrintDocumentAdapter printDocumentAdapter = webView.createPrintDocumentAdapter();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) printDocumentAdapter = webView.createPrintDocumentAdapter(title);
if(printManager != null)
{
PrintAttributes printAttributes = new PrintAttributes.Builder().build();
PrintJob printJob = printManager.print(title, printDocumentAdapter, printAttributes);
List<PrintJob> printJobs = printManager.getPrintJobs();
printJobs.add(printJob);
}
}
else
{
showToast(mContext.getString(R.string.mytools_printing_not_supported), 1);
}
}
示例8: printOrCreatePdfFromWebview
import android.print.PrintJob; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@SuppressWarnings("deprecation")
public PrintJob printOrCreatePdfFromWebview(WebView webview, Document document) {
String jobName = String.format("%s (%s)", document.getTitle(), _context.getString(R.string.app_name));
return super.printOrCreatePdfFromWebview(webview, jobName);
}