【问题标题】:Brother SDK Calling PrintImage causes JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstringBrother SDK 调用 PrintImage 导致 JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring
【发布时间】:2020-02-13 03:48:42
【问题描述】:

目前正在为标签打印机使用 Brother SDK,当我调用 Asset Manager 时,会出现位图,但在解析为打印图像时会崩溃。

if (myPrinter.startCommunication()) {
AssetManager assetManager = getAssets();
          Bitmap bitmap = null;
          try{
              bitmap = BitmapFactory.decodeStream(new BufferedInputStream(assetManager.open("meme.bmp")));
             }catch(Exception e){
               e.printStackTrace();
             }
          PrinterStatus result = myPrinter.printImage(bitmap);
       if (result.errorCode != ErrorCode.ERROR_NONE) {
         Log.d("TAG", "ERROR - " + result.errorCode);
       }
         myPrinter.endCommunication();
}

Stack Readout

Debugger printout, with Image Preview.

【问题讨论】:

  • 位图是否为空?
  • 我添加了调试器打印输出,图像可以预览,但它是空的,所以不确定发生了什么。
  • 是时候用调试器看看JNI报错中提到的方法的实现了。
  • 我在代码库的其他地方测试了资产管理器代码部分,它的返回方式也与上面的调试器相同。是否有另一种方式将 bmp 加载到 Bitmap 数据类型中。

标签: java android mobile


【解决方案1】:

对于任何人,即使他们确保他们已获得写入权限,也会陷入困境,这与 b-PAC 试图创建的工作路径有关。

默认路径为:/storage/emulated/0/com.brother.ptouch.sdk/template

只需在 PrinterInfo 对象中定义自己的路径。像这样设置workPath 变量:

PrinterInfo mPrintSettings = mPrinter.getPrinterInfo();
mPrintSettings.workPath = "your/custom/work/path";

它在文件中说,如果你这样做,你甚至不需要许可。但无论如何我都会保留它。

【讨论】:

  • 这太棒了!修复了我们的 Brother 打印机无法在 Android 10 上运行的问题。一旦我输入了workPath,它就会再次开始工作。非常感谢!
【解决方案2】:

我也有这个问题。您是否确保已授予 android.permission.WRITE_EXTERNAL_STORAGE 权限。 在清单文件中有这个是不够的,但是通过请求用户的许可,这个特定的错误就消失了。

Credit to this post on SO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 2017-02-13
    • 1970-01-01
    相关资源
    最近更新 更多