Folder
* Package Android.printservice
* Public abstract class Printservice
* Public abstract class Printerdiscoverysession
* Public final class Printerinfo
* Public final class Printerid
* Public final class PrintJob
* Public final class Printjobinfo
* Public final class Printercapabilitiesinfo
* Public final class PrintDocument
* Public final class Printdocumentinfo
Original link: https://developer.android.com/reference/android/printservice/package-summary.html
Package
Android.printservice
The class that provides the print service implementation. The print service is a plug-in (plug-in components) that can communicate with some standard protocols and printers.
These services are like a bridge. is between the system and the printer. As a result, the specific implementation of the printer and printing protocol is decoupled from the system and can be independently developed and updated.
A print service implementation should be based on a PrintService
class. and to implement its abstract method (abstract methods).
In addition, the print service must manage PrintJob
(print task) classes by convention.
The system is responsible for starting and stopping a print service. This action depends on whether the printer managed by the Print Service has an active print job (active print jobs). The print service also runs printer discovery operations in a timely manner to ensure a good user experience.
The interaction between the system and the Print service is encapsulated in an instance of the class during the printer discovery process PrinterDiscoverySession
. Created by the Print service when required by the system.
Class (Classes) PrintDocument
From the point of view of a print service, this class represents a file to be printed (document).
Printerdiscoverysession
This class encapsulates the interaction of a print service and system during the printer discovery process.
PrintJob
For a print service, this class represents a print job.
Printservice
This basic class is used to implement printing services.
Original link: https://developer.android.com/reference/android/printservice/PrintService.html
Public abstract class
Printservice
Extends Service
java.lang.Object ? android.content.Context ? android.content.ContextWrapper ? android.app.Service ? android.printservice.PrintService
Category Overview Class overview
This is the underlying class for the print services implementation.
A print service knows how to find a printer. and communicate with one or more printers through one or more protocols.
Printer Discovery Printer Discovery
A print service is responsible for discovering the printer and joining the discovered printer. Remove the joined printer and update the joined printer.
When the system needs the printer that your service manages, the system calls onCreatePrinterDiscoverySession()
, in this function you must return an PrinterDiscoverySession
object instance (instance).
The returned session (session) encapsulates the system and the content of your service interaction. Includes actions in the printer discovery phase.
Many other descriptive narratives of this interaction. PrinterDiscoverySession
documentation.
For each of the print Discovery sessions (session). All printers must be joined, because the system will not be retained after the session. So. Each printer detected by the print service should be added. And added only once in a discovery session. Only printers that have been added have the ability to be removed (removed) or updated (updated).
The removed printer can also be added again.
Printing work print jobs
When a new print job is assigned to the printer managed by the Print service, the print job is put into the queue (queued). That is, ready to be processed by the Print service.
You will receive a onPrintJobQueued(PrintJob)
call. The print service may handle this print job immediately or put it in a schedule. The print service's entire activity is printed in a list that can be obtained by invoking it getActivePrintJobs()
. Active print jobs (active print jobs) are those that are in the queue or have started.
When a print service is processing a print job. The Print service is responsible for setting the appropriate status for the print job.
First, a print job is in the queue, which PrintJob.isQueued()
returns True. This means that the document to be printed has been systematically scheduled (spooled), and the print service can handle it at any time.
You can PrintJob.getDocument()
get the document you want to print by calling it. The data in this can be PrintDocument.getData()
read. When the print service starts printing data, the print job status should be set to start (started) by calling start()
function settings. After setting, PrintJob.isStarted()
it should return true. After the successful completion of the work. The print job should be marked as finished (completed) by invoking the PrintJob.complete()
settings. After setting, PrintJob.isCompleted()
it should return true.
If it fails, the print job should be marked as failed (failed) by invoking the PrintJob.fail( String)
settings.
After setting, it PrintJob.isFailed()
should return true.
Assume that a print job (print job) is in the queue (queued) or started (started). The Print service receives a call when the user requests that it be canceled onRequestCancelPrintJob(PrintJob)
. This request in the service wants to do its best to cancel the job. If the job is successfully canceled, its status needs to PrintJob.cancel()
be flagged for cancellation.
After the tag. PrintJob.isCacnelled()
should return true.
Life cycle Lifecycle
The life cycle of a print service is managed only by the system and is based on a defined lifecycle activity. Other than that. Starting or stopping a print service is triggered only by a specific user behavior, which is to enable (enabling) or disable (disabling) services in the device settings.
After the system binds (binds) a print service, the system is called onConnected()
.
This method can be overridden by the client (clients) to run bindings-related operations. And after the system is unbound (unbinds) a print service, the system is called onDisconnected()
.
This method can be overridden by the client (clients) to run cleanup operations related to unbind (unbinding). None of your work should be done after the system has been disconnected from your print service, and the service will be killed at any time as it recycles memory. When the print service manages the printer that has active printing work. The system does not disconnect from it.
Statement Declaration
A print service, like any other service, needs to be declared in Androidmanifest.xml. But it also has to deal with android.printservice.PrintService
the action-intent.
Failure of this intent declaration causes the system to ignore the print service.
In addition, a print service must request android.permission.BIND_PRINT_SERVICE
permissions to ensure that only the system can bind (BIND) it. Declaring this failure will cause the system to ignore the print service. Here is an example of a declaration:
<service android:name=".MyPrintService" android:permission="android.permission.BIND_PRINT_SERVICE"> <intent-filter> <action android:name="android.printservice.PrintService" /> </intent-filter> </service>
Configuring the Configuration
A print service can be configured through its own Definition Settings page (setting activity), which provides its own definition settings.
An activity that joins a printer can be manually added to the printer. Vendor name, and so on. The system is responsible for starting the setup and adding the printer's activities at the appropriate time.
A print service in the Declaration, to provide a mainfest meta-data
. This is the way to specify the above activities. A service meta-data
tag (tag) declaration such as the following see:
<service android:name=". Myprintservice "android:permission=" Android.permission.BIND_PRINT_SERVICE "> <intent-filter> <action android:name="Android.printservice.PrintService" /> </intent-filter> <meta-data android:name= "android.printservice" android:resource=" @xml/printservice " /> </Service>
A lot of other details about configuring your print service via Meta-data are available SERVICE_META_DATA
<print-service>
.
tip: All callback Functions (callbacks) In this class are run in the main thread of the program. You should also call (Invoke) the method in this class in the main thread of the program.
Original link: https://developer.android.com/reference/android/printservice/PrinterDiscoverySession.html
Public abstract class
Printerdiscoverysession
Extends Object
java.lang.Object ? android.printservice.PrinterDiscoverySession
Category Overview Class overview
This class encapsulates the interactive content of a print service and system in the printer look-up (printer discovery) process. In the printer search process, you (referring to this class) are responsible for adding the discovered printers, removing the previously joined but invalid printers, and updating the printers that have been added.
During the lifetime of this session, you may be asked to start and stop looking for a printer multiple times.
You will be called onStartPrinterDiscovery(List)
to start looking for the printer and then be called onStopPrinterDiscovery()
to stop looking for the printer.
When the system no longer needs this session to find the printer, you will receive the onDestroy()
call. At this point. The system will no longer invoke this session session
, and the method in the whole session is no longer practical.
The discovered printers are joined by calling addPrinters(List)
methods.
Add a good printer removePrinters(List)
to remove by calling.
The attributes and functions of the added printer (properties or capabilities) are addPrinters(List)
updated by calling.
These joined printers can be acquired by getPrinters()
. The printer returned in this method is the latest snapshot of the printer you escalated (snapshot).
These printers are not retained after the session.
Suppose you (a tweet refers to a user.) Before referring to this class) need to update some printers, the system will be called onValidatePrinters(List)
.
You might just add a printer without configuring its feature (capabilities). This mechanism allows you to avoid querying all printers in order to configure the functionality of the printer. Instead, you can simply query the functionality of a printer when necessary.
For example, a printer is selected by the user and the system asks you to update the printer.
You do not need to provide the features of the printer when verifying the printer, but you can do so.
Assuming that the system continues to monitor the latest state of the printer, you will receive a onStartPrinterStateTracking(PrinterId)
call.
Once received, you must keep the system up to date with the latest state and functionality of the printer. When you previously joined the printer without providing its features, you must update the content at this point. Otherwise, the printer will be ignored. When the system no longer needs to get the latest state of the printer, you will receive a onStopPrinterStateTracking(PrinterId)
call.
tip: All callback functions in this class are run on the main thread of the program. You also call these functions on the main thread when you use them yourself.
Public final class
Printerinfo
Extends Object
Implements Parcelable
java.lang.Object ? android.print.PrinterInfo
Category Overview Class overview
This class is a descriptive narrative of a printer.
Instances of this class are created by the Print service. Report the printers they manage to the system. There are two parts of the information in this class. The first part. Printer properties, column such as name (name), ID (number), status (state), description (descriptive narration). The second part, printer capabilities (printer capability). Printer capabilities describes the various print modes supported by the printer, such as media sizes (probably paper size), margins (left white size), etc.
Public final class
Printerid
Extends Object
Implements Parcelable
java.lang.Object ? android.print.PrinterId
Category Overview Class overview
This class represents a unique number for a printer
Public final class
PrintJob
Extends Object
java.lang.Object ? android.printservice.PrintJob
Category Overview Class overview
From the point of view of a print service. This class represents a print job. It provides APIs to observe the status of print tasks and to run operations on print tasks.
Tip: All methods inside the class must be run in the main thread of the application.
Public final class
Printjobinfo
Extends Object
Implements Parcelable
java.lang.Object ? android.print.PrintJobInfo
Category Overview Class overview
This class represents a specific descriptive narrative of a print task.
The status of the printer task includes some configuration. For example: its ID (number), printing properties. This is used to generate some content and so on. Note that the print task status may change over time. This class represents only one moment in the state (snapshot).
Public final class
Printercapabilitiesinfo
Extends Object
Implements Parcelable
java.lang.Object ? android.print.PrinterCapabilitiesInfo
Category Overview Class overview
This class represents the ability of a printer (capabilities).
An instance of this class is created by a print service to report on the capabilities of the printer it manages.
The ability of a printer indicates how it prints the content.
For example: What paper size does the printer support (media sizes), the minimum white space for the printer design (the minimal margins), and so on.
Public final class
PrintDocument
Extends Object
java.lang.Object ? android.printservice.PrintDocument
Category Overview Class overview
For a print service, this class represents a file to be printed.
It provides APIs to query the file and the data it includes.
Tip: All methods must be run in the main thread of the program.
Public final class
Printdocumentinfo
Extends Object
Implements Parcelable
java.lang.Object ? android.print.PrintDocumentInfo
Category Overview Class overview
This class encapsulates information about a document that is related to printing.
This meta-data
(meta data) is used by the platform (platform) and the Print service to compose and interact with the printer.
For example, this class includes the number of pages in a document, and the number of document pages presented to the user so that they can select a range of prints. A print service may optimize printing for content types, such as documents or photos.
Instances of this class are created by the application that needs to be printed. The callback function is called after the content is successfully typeset (laying out the contents) PrintDocumentAdapter.LayoutResultCallback.onLayoutFinished( PrintDocumentInfo, boolean)
. This process runs in PrintDocumentAdapter.onLayout(PrintAttributes, PrintAttributes, android.os.CancellationSignal, PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle)
.
One example of using the sample is as follows:
... public void onlayout (Printattributes oldattributes, Printattributes newattributes, cancellationsignal cancellationsignal, LayoutResult Callback Callback, Bundle metadata) {//assume the app defined a Layoutresult C Lass which contains //the layout result data and the content is a document. Layoutresult result = Dosomelayoutwork (); Printdocumentinfo info = new printdocumentinfo. Builder ( "printed_file.pdf" ). setContentType (Printdocumentinfo.content_type _document). Setpagecount (Result.getpagecount ()). build (); Callback.onlayoutfinished (Info, result.getcontentchanged ()); } . . .
Android_printservice_api_ Partial translation