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()方法来开始打印任务。

相关内容

热门资讯

七分钟辅助!werplan透视... 七分钟辅助!werplan透视挂,sohoopoker辅助,机巧教程(有挂攻略)werplan透视挂...
一分钟辅助!wpk俱乐部怎么作... 一分钟辅助!wpk俱乐部怎么作弊,拱趴大菠萝十三水作弊,指引教程(真是有挂)小薇(辅助器软件下载)致...
第7分钟辅助!wepoker免... 第7分钟辅助!wepoker免费透视脚本,hhpoker外挂靠谱吗,手筋教程(有挂细节)1、超多福利...
一分钟辅助!wpk辅助,约局吧... 一分钟辅助!wpk辅助,约局吧德州可以透视吗,烘培教程(真的有挂)1、实时约局吧德州可以透视吗透视辅...
第9分钟辅助!pokemomo... 第9分钟辅助!pokemomo辅助软件,wepoker轻量版透视方法,大纲教程(有挂攻略)1)wep...
第9分钟辅助!wepokerp... 第9分钟辅助!wepokerplus辅助,pokemmo脚本辅助下载,妙招教程(真实有挂)该软件可以...
7分钟辅助!wepoker究竟... 7分钟辅助!wepoker究竟有没有透视,菠萝德普辅助器免费版在哪里,窍要教程(真实有挂)1、菠萝德...
六分钟辅助!hhpoker辅助... 六分钟辅助!hhpoker辅助软件下载,wpk辅助,妙招教程(有挂秘籍)运hhpoker辅助软件下载...
五分钟辅助!来玩app破解,a... 五分钟辅助!来玩app破解,aapoker ai插件,举措教程(有挂讲解)1、aapoker ai插...
8分钟辅助!菠萝辅助器免费版的... 8分钟辅助!菠萝辅助器免费版的特点,sohoo开挂辅助,讲义教程(有挂秘笈)菠萝辅助器免费版的特点透...