I have updated my windows environment from 8 to 10 and found that the default printer is not being returned and a different one is returned instead.
I have turned off the "Let windows manage my default printer" setting, but still not getting the default printer.
I have the following code:
private void testPrinter() {
PrintService[] array = PrintServiceLookup.lookupPrintServices(null, null);
for(PrintService ps : array){
System.out.println(ps.getName());
}
}
In this test, I get a list of printers as following:
Send to one note
Microsoft XPS Document Writer
HP printer
Epson Printer (which is set as my default printer in windows)
However, in the following test:
PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
System.out.println(ps.getName());
I get the HP printer, which is not my default printer!!! No matter which printer I chose as a default, the HP printer is returned always
I went through the java API for lookupDefaultPrintService method and it says the following:
Locates the default print service for this environment. This may return null. If multiple lookup services each specify a default, the chosen service is not precisely defined, but a platform native service, rather than an installed service, is usually returned as the default. If there is no clearly identifiable platform native default print service, the default is the first to be located in an implementation-dependent manner.
This may include making use of any preferences API that is available as part of the Java or native platform. This algorithm may be overridden by a user setting the property javax.print.defaultPrinter. A service specified must be discovered to be valid and currently available to be returned as the default.
In windows 8, there was no issue with returning the default printer. After updating I'm getting this problem. How can I solve this issue?