Android打印任务空的意图
创始人
2024-10-07 03:00:49
0

要创建一个Android打印任务空的意图,可以使用以下代码示例:

private void printEmptyDocument() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
        String jobName = getString(R.string.app_name) + " Document";

        PrintDocumentAdapter printAdapter = new PrintDocumentAdapter() {
            @Override
            public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
                // Leave it empty to create an empty document
            }

            @Override
            public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
                // Respond with the print document info, such as number of pages
                PrintDocumentInfo.Builder builder = new PrintDocumentInfo.Builder("file name");
                builder.setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
                        .setPageCount(0) // Set page count to 0 for empty document
                        .build();

                callback.onLayoutFinished(builder.build(), false);
            }
        };

        printManager.print(jobName, printAdapter, null);
    }
}

在上面的代码示例中,我们通过使用PrintManager类来获取打印管理器的实例。然后,我们创建一个打印作业的名称,并创建一个PrintDocumentAdapter的实例来处理打印文档的布局和写入。

onWrite()方法中,我们将其保持为空,这样将创建一个空的打印文档。

onLayout()方法中,我们使用PrintDocumentInfo.Builder来构建打印文档的信息。我们设置文档的内容类型为PrintDocumentInfo.CONTENT_TYPE_DOCUMENT,并将页面数设置为0,以表示空文档。最后,我们调用callback.onLayoutFinished()方法来通知打印系统打印文档的布局已经完成。

最后,我们调用printManager.print()方法来开始打印任务。

相关内容

热门资讯

三分钟辅助!智星菠萝可以辅助吗... 三分钟辅助!智星菠萝可以辅助吗,德州真人透视脚本,绝活儿教程(有挂方法)三分钟辅助!智星菠萝可以辅助...
第8分钟辅助!wepoker有... 第8分钟辅助!wepoker有没有辅助,hhpoker必备开挂,法门教程(真实有挂)1、超多福利:超...
4分钟辅助!wejoker开挂... 4分钟辅助!wejoker开挂,sohoo poker辅助器,模板教程(有挂技巧)1、首先打开soh...
第七分钟辅助!wpk模拟器,w... 第七分钟辅助!wpk模拟器,wpk透视辅助靠谱吗,妙计教程(有挂细节)在进入wpk透视辅助靠谱吗软件...
第七分钟辅助!wepoker开... 第七分钟辅助!wepoker开辅助能查到吗,aapoker辅助器怎么用,经验教程(确实有挂)1、起透...
第7分钟辅助!wepoker智... 第7分钟辅助!wepoker智能辅助插件,哈糖大菠萝开挂,妙计教程(有挂详细)1)wepoker智能...
第三分钟辅助!hhpoker视... 您好,hhpoker视频巡查真的假的这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275...
第八分钟辅助!pokemomo... 第八分钟辅助!pokemomo辅助软件,扑克之星辅助,诀窍教程(真实有挂)该软件可以轻松地帮助玩家将...
第4分钟辅助!wepoker怎... 第4分钟辅助!wepoker怎么提高运气,wepoker辅助器,烘培教程(有挂解惑)1、实时wepo...
6分钟辅助!德州局HHpoke... 6分钟辅助!德州局HHpoker透视脚本,sohoo辅助,操作教程(有挂猫腻)德州局HHpoker透...