【问题标题】:Error thrown while printing to IPP printer in android using Cups4j使用 Cups4j 在 android 中打印到 IPP 打印机时引发错误
【发布时间】:2019-11-27 07:47:45
【问题描述】:

我正在尝试使用来自 android 的 Cups4j 打印到安装在 linux 机器上的 IPP 打印机。这是代码,我或多或少只是复制了他们在他们的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();
}

当我尝试打印时出现以下错误

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)

或者是否有任何其他库可以处理来自 android 的 IPP 打印?

【问题讨论】:

  • 我没有遇到这样的问题。但我认为这可能是 cups4j 和 apache http 客户端之间的问题。尝试使用不同版本的 google 以确保这些包之间的兼容性。

标签: java android printing ipp-protocol cups4j


【解决方案1】:

Cups4j 不支持 Android。您可能会发现 forks 添加了对 Android 的支持。

ipp-client-kotlin 从 1.6 版开始支持 Android,应该可以开箱即用。

【讨论】:

    猜你喜欢
    • 2016-08-16
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 2016-01-07
    • 2012-03-31
    • 1970-01-01
    相关资源
    最近更新 更多