Error thrown while printing to IPP printer in android using Cups4j

914 Views Asked by At

I'm trying to print to an IPP printer installed on a linux machine using Cups4j from android. Here's the code, I more or less just copied what they have written on their github page.

ByteArrayOutputStream os = stvoriRacun(narudzba, djelatnik, brStola);
try {
    CupsClient cupsClient = new CupsClient("192.168.68.180", 631);
    URL printerURL = new URL("http://192.168.68.180:631/printers/bixolonIPP");
    CupsPrinter cupsPrinter = cupsClient.getPrinter(printerURL);
    Map<String, String> attributes = new HashMap<>();
    attributes.put("compression", "none");
    attributes.put("job-attributes", "print-quality:enum:3#fit-to-page:boolean:true#sheet-collate:keyword:collated");

    PrintJob printJob = new PrintJob.Builder(os.toByteArray())
            .jobName("job-name")
            .userName("user-name")
            .copies(2)
            .pageRanges("1-3")
            .duplex(false)
            .portrait(false)
            .color(true)
            .pageFormat("iso-a4")
            .resolution("300dpi")
            .attributes(attributes)
            .build();
}catch (Exception e){
    e.printStackTrace();
}

When I try to print i get the following error

07-18 12:26:29.294 30378-30529/com.appid.apps E/AndroidRuntime: FATAL EXCEPTION: Thread-8
                                                              Process: com.appid.apps, PID: 30378
                                                              java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes3.dex)
                                                                  at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
                                                                  at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
                                                                  at org.cups4j.operations.IppOperation.sendRequest(IppOperation.java:176)
                                                                  at org.cups4j.operations.IppOperation.sendRequest(IppOperation.java:131)
                                                                  at org.cups4j.operations.IppOperation.request(IppOperation.java:67)
                                                                  at org.cups4j.operations.cups.CupsGetPrintersOperation.getPrinters(CupsGetPrintersOperation.java:56)
                                                                  at org.cups4j.CupsClient.getPrinters(CupsClient.java:106)
                                                                  at org.cups4j.CupsClient.getPrinter(CupsClient.java:166)
                                                                  at com.appid.apps.IPPPrinter.connect(IPPPrinter.java:107)
                                                                  at com.appid.apps.Printing$1.run(Printing.java:604)
                                                                  at java.lang.Thread.run(Thread.java:764)

Alternatively is there any other library that deals with IPP printing from android?

1

There are 1 best solutions below

1
On

Cups4j does not support Android. You might find forks that add support for Android.

The library ipp-client-kotlin supports Android since version 1.6 and should work out of the box.

Examples written in Java or Kotlin are available in ipp-samples