Android.Print.PrintDocumentAdapter.OnWrite Method
Called when specific pages of the content should be written in the form of a PDF file to the given file descriptor.

Syntax

[Android.Runtime.Register("onWrite", "([Landroid/print/PageRange;Landroid/os/ParcelFileDescriptor;Landroid/os/CancellationSignal;Landroid/print/PrintDocumentAdapter$WriteResultCallback;)V", "GetOnWrite_arrayLandroid_print_PageRange_Landroid_os_ParcelFileDescriptor_Landroid_os_CancellationSignal_Landroid_print_PrintDocumentAdapter_WriteResultCallback_Handler")]
public abstract void OnWrite (PageRange[] pages, Android.OS.ParcelFileDescriptor destination, Android.OS.CancellationSignal cancellationSignal, PrintDocumentAdapter.WriteResultCallback callback)

See Also

Android.OS.CancellationSignal

Parameters

pages
The pages whose content to print - non-overlapping in ascending order.
destination
The destination file descriptor to which to write.
cancellationSignal
Signal for observing cancel writing requests.
callback
Callback to inform the system for the write result.

Remarks

Called when specific pages of the content should be written in the form of a PDF file to the given file descriptor. This method is invoked on the main thread.

java Example

 cancellationSignal.setOnCancelListener(new OnCancelListener() {
     @Override
     public void onCancel() {
         // Cancel write
     }
 });
 

After you are done writing, you should close the file descriptor and invoke NoType:android/print/PrintDocumentAdapter$WriteResultCallback;Href=../../../reference/android/print/PrintDocumentAdapter.WriteResultCallback.html#onWriteFinished(android.print.PageRange[]), if writing completed successfully; or NoType:android/print/PrintDocumentAdapter$WriteResultCallback;Href=../../../reference/android/print/PrintDocumentAdapter.WriteResultCallback.html#onWriteFailed(java.lang.CharSequence), if an error occurred; or NoType:android/print/PrintDocumentAdapter$WriteResultCallback;Href=../../../reference/android/print/PrintDocumentAdapter.WriteResultCallback.html#onWriteCancelled(), if writing was cancelled in a response to a cancellation request via the passed in Android.OS.CancellationSignal. Note that you must call one of the methods of the given callback for this method to be considered complete which is you will not receive any calls to this adapter until the current write operation is complete by invoking a method on the callback instance. The callback methods can be invoked from an arbitrary thread.

One of the arguments passed to this method is a Android.OS.CancellationSignal which is used to propagate requests from the system to your application for canceling the current write operation. For example, a cancellation may be requested if the user changes a print option that may affect layout while you are performing a write operation. In such a case the system will make an attempt to cancel the current write as a layout will have to be performed which then may be followed by a write. Typically, you should register a cancellation callback in the cancellation signal. The cancellation callback will not be made on the main thread and can be registered as follows:

Note: If the printed content is large, it is a good practice to schedule writing it on a dedicated thread and register an observer in the provided Android.OS.CancellationSignal upon invocation of which you should stop writing.

[Android Documentation]

Requirements

Namespace: Android.Print
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0