简体   繁体   English

使用 Cups4j 在 android 中打印到 IPP 打印机时抛出错误

[英]Error thrown while printing to IPP printer in android using Cups4j

I'm trying to print to an IPP printer installed on a linux machine using Cups4j from android.我正在尝试使用来自 android 的 Cups4j 打印到安装在 linux 机器上的 IPP 打印机。 Here's the code, I more or less just copied what they have written on their github page.这是代码,我或多或少只是复制了他们在 github 页面上写的内容。

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?或者,是否还有其他库可以处理来自 android 的 IPP 打印?

Cups4j does not support Android. Cups4j 不支持安卓。 You might find forks that add support for Android.您可能会找到添加对 Android 支持的分叉

The library ipp-client-kotlin supports Android since version 1.6 and should work out of the box.ipp-client-kotlin从 1.6 版开始支持 Android 并且应该可以开箱即用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM