# PrintManager

Added in[API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/print/PrintManager#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/print/PrintManager#inhmethods)  

# PrintManager

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/print/PrintManager "View this page in Kotlin")\|Java

`
public

final

class
PrintManager
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.print.PrintManager |

<br />

*** ** * ** ***

System level service for accessing the printing capabilities of the platform.

### Print mechanics

The key idea behind printing on the platform is that the content to be printed should be laid out for the currently selected print options resulting in an optimized output and higher user satisfaction. To achieve this goal the platform declares a contract that the printing application has to follow which is defined by the[PrintDocumentAdapter](https://developer.android.com/reference/android/print/PrintDocumentAdapter)class. At a higher level the contract is that when the user selects some options from the print UI that may affect the way content is laid out, for example page size, the application receives a callback allowing it to layout the content to better fit these new constraints. After a layout pass the system may ask the application to render one or more pages one or more times. For example, an application may produce a single column list for smaller page sizes and a multi-column table for larger page sizes.

### Print jobs

Print jobs are started by calling the[print(java.lang.String, android.print.PrintDocumentAdapter, android.print.PrintAttributes)](https://developer.android.com/reference/android/print/PrintManager#print(java.lang.String,%20android.print.PrintDocumentAdapter,%20android.print.PrintAttributes))from an activity which results in bringing up the system print UI. Once the print UI is up, when the user changes a selected print option that affects the way content is laid out the system starts to interact with the application following the mechanics described the section above.

Print jobs can be in[created](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_CREATED),[queued](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_QUEUED),[started](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_STARTED),[blocked](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_BLOCKED),[completed](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_COMPLETED),[failed](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_FAILED), and[canceled](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_CANCELED)state. Print jobs are stored in dedicated system spooler until they are handled which is they are cancelled or completed. Active print jobs, ones that are not cancelled or completed, are considered failed if the device reboots as the new boot may be after a very long time. The user may choose to restart such print jobs. Once a print job is queued all relevant content is stored in the system spooler and its lifecycle becomes detached from this of the application that created it.

An applications can query the print spooler for current print jobs it created but not print jobs created by other applications.

Requires the[PackageManager#FEATURE_PRINTING](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_PRINTING)feature which can be detected using[PackageManager.hasSystemFeature(String)](https://developer.android.com/reference/android/content/pm/PackageManager#hasSystemFeature(java.lang.String)).

<br />

**See also:**

- [PrintJob](https://developer.android.com/reference/android/print/PrintJob)
- [PrintJobInfo](https://developer.android.com/reference/android/print/PrintJobInfo)

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                   ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                   ||
|---------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[List](https://developer.android.com/reference/java/util/List)`<`[PrintJob](https://developer.android.com/reference/android/print/PrintJob)`>` | ` `[getPrintJobs](https://developer.android.com/reference/android/print/PrintManager#getPrintJobs())`() ` Gets the print jobs for this application.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` boolean`                                                                                                                                        | ` `[isPrintServiceEnabled](https://developer.android.com/reference/android/print/PrintManager#isPrintServiceEnabled(android.content.ComponentName))`(`[ComponentName](https://developer.android.com/reference/android/content/ComponentName)` service) ` Checks whether a given print service is enabled.                                                                                                                                                                                                                                                                                                                                                           |
| ` `[PrintJob](https://developer.android.com/reference/android/print/PrintJob)                                                                     | ` `[print](https://developer.android.com/reference/android/print/PrintManager#print(java.lang.String,%20android.print.PrintDocumentAdapter,%20android.print.PrintAttributes))`(`[String](https://developer.android.com/reference/java/lang/String)` printJobName, `[PrintDocumentAdapter](https://developer.android.com/reference/android/print/PrintDocumentAdapter)` documentAdapter, `[PrintAttributes](https://developer.android.com/reference/android/print/PrintAttributes)` attributes) ` Creates a print job for printing a[PrintDocumentAdapter](https://developer.android.com/reference/android/print/PrintDocumentAdapter)with default print attributes. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public methods

### getPrintJobs

Added in[API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public List<PrintJob> getPrintJobs ()
```

Gets the print jobs for this application.

<br />

|                                                                                                Returns                                                                                                 ||
|------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [List](https://developer.android.com/reference/java/util/List)`<`[PrintJob](https://developer.android.com/reference/android/print/PrintJob)`>` | The print job list. This value cannot be`null`. <br /> |

**See also:**

- [PrintJob](https://developer.android.com/reference/android/print/PrintJob)  

### isPrintServiceEnabled

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isPrintServiceEnabled (ComponentName service)
```

Checks whether a given print service is enabled. The provided service must share UID with the calling package, otherwise a[SecurityException](https://developer.android.com/reference/java/lang/SecurityException)is thrown.

<br />

|                           Parameters                           ||
|-----------|-----------------------------------------------------|
| `service` | `ComponentName`: This value cannot be`null`. <br /> |

|                           Returns                            ||
|-----------|---------------------------------------------------|
| `boolean` | true if the given print service is enabled <br /> |

### print

Added in[API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public PrintJob print (String printJobName, 
                PrintDocumentAdapter documentAdapter, 
                PrintAttributes attributes)
```

Creates a print job for printing a[PrintDocumentAdapter](https://developer.android.com/reference/android/print/PrintDocumentAdapter)with default print attributes.

Calling this method brings the print UI allowing the user to customize the print job and returns a[PrintJob](https://developer.android.com/reference/android/print/PrintJob)object without waiting for the user to customize or confirm the print job. The returned print job instance is in a[created](https://developer.android.com/reference/android/print/PrintJobInfo#STATE_CREATED)state.

This method can be called only from an[Activity](https://developer.android.com/reference/android/app/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](https://developer.android.com/reference/android/print/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.

**Note:** Calling this method will bring the print dialog and the system will connect to the provided[PrintDocumentAdapter](https://developer.android.com/reference/android/print/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.

<br />

<br />

|                                                         Parameters                                                         ||
|-------------------|---------------------------------------------------------------------------------------------------------|
| `printJobName`    | `String`: A name for the new print job which is shown to the user. This value cannot be`null`. <br />   |
| `documentAdapter` | `PrintDocumentAdapter`: An adapter that emits the document to print. This value cannot be`null`. <br /> |
| `attributes`      | `PrintAttributes`: The default print job attributes or`null`. <br />                                    |

|                                                                 Returns                                                                 ||
|----------------------------------------------------------------------------|-------------------------------------------------------------|
| [PrintJob](https://developer.android.com/reference/android/print/PrintJob) | The created print job on success or null on failure. <br /> |

|                                                                                                 Throws                                                                                                 ||
|--------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | If not called from an[Activity](https://developer.android.com/reference/android/app/Activity). |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | If the print job name is empty or the document adapter is null.                                |

**See also:**

- [PrintJob](https://developer.android.com/reference/android/print/PrintJob)