ここでは、デバイスのリストを取得するようにコーディングし、各デバイスのステータスを確認します
DocFlavor myFormat = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService[] services =PrintServiceLookup.lookupPrintServices(myFormat, aset);
System.out.println("The following printers are available");
for (int i=0;i<services.length;i++) {
PrintService printService = services[i];
PrintServiceAttributeSet printServiceAttributes = printService.getAttributes();
PrinterState printerState =
(PrinterState)printServiceAttributes.get(PrinterState.class);
if (printerState != null){
System.out.println(services[i].getName() + " is online");
} else {
System.out.println(services[i].getName() + " is offline");
}
}
しかし、問題は、プリンターのスイッチがオンまたはオフになっていても、ステータスが「オフライン」になるたびに発生することです