PrintManager.Print(String, PrintDocumentAdapter, PrintAttributes) Method

Definition

Creates a print job for printing a PrintDocumentAdapter with default print attributes.

[Android.Runtime.Register("print", "(Ljava/lang/String;Landroid/print/PrintDocumentAdapter;Landroid/print/PrintAttributes;)Landroid/print/PrintJob;", "")]
public Android.Print.PrintJob Print (string printJobName, Android.Print.PrintDocumentAdapter documentAdapter, Android.Print.PrintAttributes? attributes);
[<Android.Runtime.Register("print", "(Ljava/lang/String;Landroid/print/PrintDocumentAdapter;Landroid/print/PrintAttributes;)Landroid/print/PrintJob;", "")>]
member this.Print : string * Android.Print.PrintDocumentAdapter * Android.Print.PrintAttributes -> Android.Print.PrintJob

Parameters

printJobName
String

A name for the new print job which is shown to the user.

documentAdapter
PrintDocumentAdapter

An adapter that emits the document to print.

attributes
PrintAttributes

The default print job attributes or null.

Returns

The created print job on success or null on failure.

Attributes

Exceptions

If not called from an Activity.

If the print job name is empty or the document adapter is null.

Remarks

Creates a print job for printing a PrintDocumentAdapter with default print attributes.

Calling this method brings the print UI allowing the user to customize the print job and returns a PrintJob object without waiting for the user to customize or confirm the print job. The returned print job instance is in a PrintJobInfo#STATE_CREATED created state.

This method can be called only from an Activity. The rationale is that printing from a service will create an inconsistent user experience as the print UI would appear without any context.

Also the passed in PrintDocumentAdapter will be considered invalid if your activity is finished. The rationale is that once the activity that initiated printing is finished, the provided adapter may be in an inconsistent state as it may depend on the UI presented by the activity.

The default print attributes are a hint to the system how the data is to be printed. For example, a photo editor may look at the photo aspect ratio to determine the default orientation and provide a hint whether the printing should be in portrait or landscape. The system will do a best effort to selected the hinted options in the print dialog, given the current printer supports them.

<strong>Note:</strong> Calling this method will bring the print dialog and the system will connect to the provided PrintDocumentAdapter. If a configuration change occurs that you application does not handle, for example a rotation change, the system will drop the connection to the adapter as the activity has to be recreated and the old adapter may be invalid in this context, hence a new adapter instance is required. As a consequence, if your activity does not handle configuration changes (default behavior), you have to save the state that you were printing and call this method again when your activity is recreated.

Java documentation for android.print.PrintManager.print(java.lang.String, android.print.PrintDocumentAdapter, android.print.PrintAttributes).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also