HPInc / jipp

A Java-compatible implementation of IPP
MIT License
153 stars 42 forks source link

How to use this library to search and print to wifi printers (android) #105

Open IvanJanjik opened 4 years ago

IvanJanjik commented 4 years ago

Hi,

I need to create an android application, with basic functionality that when the user taps print(UI button) the app should automatically send print requests to some printer, with no user input in printer selection at that exact moment and no print preview should be displayed. There could be printer selection(configuration) but it should not bother the user every time it wants to print (it should ask the user for printer selection only one time or occasionally).

So after some research, I found out about this library and it seems like the thing I need. I tried to implement it but no luck, I don't know how to use it to scan for available printers and their Uri.

I get this error trying to send print to HPLaserJetP1102W : java.net.SocketTimeoutException: connect timed out W/System.err: at com.ivanjanikj.bistroprinting.HttpIppClientTransport.sendData(HttpIppClientTransport.java:42)

I have created HttpIppClientTransport exactly like this example -> https://github.com/HPInc/jipp/blob/master/sample/jprint/src/main/java/sample/HttpIppClientTransport.javri I think the problem is that I'm using the wrong Uri when creating this code block { URI uri = URI.create("http://192.168.1.100:631/ipp/print"); IppPacket printRequest = IppPacket.printJob(uri) .putOperationAttributes(documentFormat.of("application/pdf"))) .build(); transport.sendData(uri, new IppPacketData(printRequest, new FileInputStream(inputFile))); }

My question is: How to find the URI of every WIFI printer using this library, is there some method that I can use, that I'm not aware of?

Thank you

GladeDiviney commented 4 years ago

This library doesn't implement discovery at present. In Android you can use JMDNS (a separate Java library) or if you are targeting modern Android OS only, NsdManager.

I'm leaving this open because implementing discovery using either method would be a good addition.

gmuth commented 3 years ago

This demonstrates how to discover ipp printers using bonjour/zeroconf: https://github.com/gmuth/ipp-samples/blob/main/src/main/kotlin/mdns/DiscoverIppPrinters.kt