gpt4 book ai didi

Android PrintManager 获取回调

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:09:51 28 4
gpt4 key购买 nike

我正在使用 PrintManager 打印网页,我的 Activity 如何在打印成功后获得回调?我正在使用这段代码:

    // 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());
// Save the job object for later status checking
//mPrintJobs.add(printJob);

最佳答案

围绕从 webView 接收的 PrintDocumentAdapter 创建一个包装器。然后你可以在 onFinish() 中放置一个钩子(Hook)。

public class PrintDocumentAdapterWrapper extends PrintDocumentAdapter{

private final PrintDocumentAdapter delegate;
public PrintDocumentAdapterWrapper(PrintDocumentAdapter adapter){
super();
this.delegate = adapter;
}

public void onFinish(){
delegate.onFinish();
//insert hook here
}

//override all other methods with a trivial implementation calling to the delegate
}

下面是如何在您的代码中使用它:

// Get a PrintManager instance
PrintManager printManager = (PrintManager) this.getSystemService(Context.PRINT_SERVICE);

// Get a print adapter instance and wrap it in my own adapter
PrintDocumentAdapter printAdapter = new PrintDocumentAdapterWrapper(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());
// Save the job object for later status checking
//mPrintJobs.add(printJob);

关于Android PrintManager 获取回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30742051/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com