android JNI在Brother SDK上检测到应用程序错误

gzjq41n4  于 2023-10-14  发布在  Android
关注(0)|答案(2)|浏览(105)

我试图在我的应用程序中的兄弟SDK打印图像。
下面是我代码:

`myPrinterInfo = myPrinter.getPrinterInfo();
        myPrinterInfo.printerModel = PrinterInfo.Model.QL_810W;
        myPrinterInfo.port = PrinterInfo.Port.NET;
        myPrinterInfo.printMode = PrinterInfo.PrintMode.FIT_TO_PAGE;
        myPrinterInfo.paperSize = PrinterInfo.PaperSize.CUSTOM;
        myPrinterInfo.labelNameIndex = 5;
        myPrinterInfo.isAutoCut = false;
        myPrinterInfo.isCutAtEnd = false;
        myPrinterInfo.orientation = PrinterInfo.Orientation.PORTRAIT;
        myPrinterInfo.valign = PrinterInfo.VAlign.TOP;
        myPrinterInfo.align = PrinterInfo.Align.LEFT;
        myPrinterInfo.halftone = PrinterInfo.Halftone.THRESHOLD;
        myPrinterInfo.ipAddress = "192.168.1.146";
        myPrinterInfo.thresholdingValue = 127;
        myPrinterInfo.pjCarbon = false;
        myPrinterInfo.pjDensity = 5;
        myPrinterInfo.pjFeedMode = PrinterInfo.PjFeedMode.PJ_FEED_MODE_FIXEDPAGE;
        myPrinterInfo.pjPaperKind = PJ_CUT_PAPER;
        myPrinterInfo.rollPrinterCase = PrinterInfo.PjRollCase.PJ_ROLLCASE_OFF;
        myPrinterInfo.paperPosition = PrinterInfo.Align.CENTER;
        myPrinterInfo.numberOfCopies = 1;

我使用62 mmx 100 mm纸卷,我得到了这个错误消息:
JNI在应用程序中检测到错误:GetStringUTFChars收到NULL jstring 08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:在调用GetStringUTFChars 08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:从boolean com.brother.ptouch.sdk.JNIWrapper.writeByteInFile(int[],int,java.lang.String,boolean)08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:“AsyncTask #1”prio=5 tid=10 Runnable 08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:|group=“main”sCount=0 dsCount=0 obj=0x12c99460 self=0xe9594500 08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:|sysTid=31584 nice=10 cgrp=bg_non_interactive sched=0/0 handle=0xe0b65930 08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:|国家=R schedstat=(80462688 29252686 258)utm=5 stm=3 core=2 HZ=100 08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:|stack=0xe0a63000-0xe0a65000 stackSize=1038KB 08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:|holded mutexes=“mutator lock”(shared holded)08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:本机:#00 pc 0035adcf /system/lib/libart.so(_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiPKcPNS_9ArtMethodEPv+126)08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:本机:#01 pc 0033bdeb /system/lib/libart.so(_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+138)08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:本机:#02 pc 0024ef71 /system/lib/libart.so(ZN3art9JavaVMExt8JniAbortEPKcS2+900)08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:本机:#03 pc 0024f607 /system/lib/libart.so(_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+54)08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:本机:#04 pc 000fbe5d /system/lib/libart.so(_ZN3art11ScopedCheck6AbortFEPKcz+28)08-10 17:33:18.882 31333-31584/br.com.squarebits.brothertest E/art:本机:#05 pc 001003b9 /system/lib/libart.so(_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectCheckerEbPKcPNS_12JniValueTypeE.constprop.95 +2676)08-10 17:33:18.883 31333-31584/br.com.squarebits.brothertest E/art:本机:#06 pc 00108 cd 5/system/lib/libart.so(_ZN3art8CheckJNI17GetStringUTFCharsEP7_JNIEnvP8_jstringPh+376)
如果有人知道如何修复它,请帮助我:(

i7uq4tfw

i7uq4tfw1#

我今天也遇到了类似的问题,结果是android.permission.WRITE_EXTERNAL_PROCESSION权限没有被授予。如果您运行的是Android 6或更高版本,请检查run time permissions是否写入外部存储。在清单中声明权限是不够的。兄弟文档在其manual的末尾暗示了这一点。
8.3. Android 6兼容性自Android 6.0起,允许用户在安装后更改应用程序的权限。必须获得访问Android外部存储的权限才能使用此应用程序。

im9ewurl

im9ewurl2#

下面是我所做的步骤列表,以使打印功能并摆脱此错误。我使用的是最新的Brother SDK 4.6.4。

1. AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

2.请求权限

if (context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
  ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 8);
}

3. build.gradle

targetSdkVersion = 32

(降低到32帮助我在新设备上显示权限弹出窗口)

4. [这一个成功了]将workPath添加到打印机信息

PrinterInfo printInfo = printer.getPrinterInfo();
printInfo.workPath = "storage/emulated/0/Download/";

兄弟兄弟应该致力于开发人员的体验。希望这对你有帮助!

相关问题