0
, 나는 PDF 문서를 인쇄하기 위해 노력하고있어, 모든 것이 잘 작동, 여기에 파일인쇄 작업이 완료되었는지 확인하는 방법은 무엇입니까? 내 안드로이드 응용 프로그램에서
private void printFile(){
PrintManager printManager = (PrintManager) this.getSystemService(getApplicationContext().PRINT_SERVICE);
PrintDocumentAdapter pda = new PrintDocumentAdapter(){
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback){
OutputStream output = null;
try {
output = new FileOutputStream(destination.getFileDescriptor());
byte[] buf = _responseBody;
output.write(buf);
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
} catch (FileNotFoundException ee){
//Catch exception
} catch (Exception e) {
//Catch exception
} finally {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras){
if (cancellationSignal.isCanceled()) {
callback.onLayoutCancelled();
return;
}
PrintDocumentInfo pdi = new PrintDocumentInfo.Builder("Name of file").setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
callback.onLayoutFinished(pdi, true);
}
@Override
public void onFinish(){
System.out.println("PRINT IS FINISHED");
}
};
PrintAttributes printAttrs = new PrintAttributes.Builder().
setMediaSize(PrintAttributes.MediaSize.ISO_A6).
setMinMargins(PrintAttributes.Margins.NO_MARGINS).
build();
PrintJob printJob = printManager.print(labelID, pda, printAttrs);
}
그러나 인쇄에 내 현재의 조각입니다 인쇄가 나는를 실행하려면 완료 될 때 메서드를 다시 응용 프로그램의 이전보기로 이동하기 때문에 인쇄 작업이 완료 될 때 발생하는 이벤트를 잡아야합니다. 누군가가 어떻게 수행하는지 설명하거나 코드 스 니펫을 크게 높이 평가할 수 있습니다.
인쇄 작업이 끝날 때까지 기다리지 말고,'print()'호출이 돌아 오면 사용자가 탐색 할 것을 권한다. 프린터 정책 (장치 및 프린터) 및 상태 (예 : 걸림)에 따라 인쇄 작업이 오랫동안 완료되지 않을 수 있습니다. – CommonsWare