cordova-brother-label-printer icon indicating copy to clipboard operation
cordova-brother-label-printer copied to clipboard

Android Bluetooth support, SDK updates (testers needed)

Open gordol opened this issue 6 years ago • 15 comments

I wasn't quite happy with the state of the dev branch (lots of people have touched it, etc...) I shouldn't have accepted one of the merges for Bluetooth support because it's pulling classes from Brother's demo app, instead of relying on documentation from the SDK manual. I've taken the good bits from the dev branch, where Android is concerned, and have cleaned it up a bit.

  • Brother SDK updated to latest (removed all PDF libraries as per the manual from Brother, as modern Android supports this natively, and I'm not looking to target older Android versions with this plugin)
  • bluetooth support via findBluetoothPrinters()
  • added generic findPrinters() to find network and bluetooth printers
  • select a printer from the list of found printers via setPrinter()
  • get printer status via printerStatus()

Unfortunately, I do not have a bluetooth label printer, so I cannot test this. @ykrasnokutskiy can you give this a shot and see if it works for you? It compiles fine, but there could be runtime errors.

If someone wants to send me the funds for a QL-820NWB, I'm happy to try to get it working (if it's not working already).

gordol avatar Nov 09 '18 04:11 gordol

Hey @gordol,

I want to test the Bluetooth printer PT-P710BT on this branch with the SDK with version v3.0.13 (9/11/2018). Listing the printers was super easy, printing an test image didn't work as expected. I've encountered the same exception as described here: https://github.com/gordol/cordova-brother-label-printer/issues/32 and been trying to fix this for hours.

You commented: "Looks to me like y'all don't have the Brother Android SDK installed properly, as that library is included with it. Otherwise, it doesn't match your architecture... Either way, it's not an issue with this Cordova extension."

Can you point me in a direction how to "add the libraries manually"?

koktaildotcom avatar Mar 27 '19 10:03 koktaildotcom

@ykrasnokutskiy can you tell me how to "add the libraries manually"? Then you would be my hero.

koktaildotcom avatar Apr 02 '19 08:04 koktaildotcom

@koktaildotcom

libs:
arm64-v8a  armeabi  armeabi-v7a  BrotherPrintLibrary.aar  BrotherPrintLibrary.jar  x86	x86_64

libs/arm64-v8a:
libcreatedata.so

libs/armeabi:
libcreatedata.so

libs/armeabi-v7a:
libcreatedata.so

libs/x86:
libcreatedata.so

libs/x86_64:
libcreatedata.so

you should have a directory like that in your project. if you don't, you need to move these files from the SDK so they can be found by the linker.

gordol avatar Apr 22 '19 06:04 gordol

Thank you very much, that helped! The printer that i used isn't compatible with the SDK however.

koktaildotcom avatar Apr 23 '19 16:04 koktaildotcom

@koktaildotcom do you need a newer SDK for it to work? or is it just not compatible at all?

gordol avatar Apr 23 '19 21:04 gordol

@koktaildotcom do you need a newer SDK for it to work? or is it just not compatible at all?

I've used the Brother PT-P710BT, and that printer not compatible with the SDK.

koktaildotcom avatar Apr 24 '19 05:04 koktaildotcom

Hi @gordol ,

I tried using your branch to print on a QL-820NWB connected via Bluetooth (I'm still testing for wifi).

The first issue I ran into was the android system not being able to find libcreatedata.so:

05-16 17:30:59.804 17913-18068/com.app E/AndroidRuntime: FATAL EXCEPTION: pool-2-thread-3
    Process: com.app, PID: 17913
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libcreatedata.so"
        at java.lang.Runtime.loadLibrary(Runtime.java:366)
        at java.lang.System.loadLibrary(System.java:988)
        at com.brother.ptouch.sdk.JNIWrapper.<clinit>(JNIWrapper.java:16)
        at com.brother.ptouch.sdk.Printer.setPrinterInfo(Printer.java:1293)
        at com.threescreens.cordova.plugin.brotherPrinter.BrotherPrinter$4.run(BrotherPrinter.java:433)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)

After some research, I came accross this stackoverflow which advises putting .so files in app/src/main/jniLibs. I did it in https://github.com/stevenremot/cordova-brother-label-printer/commit/088e14f72998fa3a0f7516bbcf796596ee4077c7. This solved the issue for me.

Then, when calling the printViaSdk method, the SDK wasn't able to find the printer, even if it was detected with findPrinters and set with setPrinters. I had to ensure myPrinterInfo.macAddress was set, as you already did with myPrinterInfo.ipAddress on wifi in order for the SDK to find the printer.

Lastly, when the printer was found and the print order was sent, I got an error ERROR_WRONG_LABEL. Apparently the labelNameId must be set to a proper value for the QL-820-NWB.

I implemented a draft of API to set some label information before printing. This and the bluetooth fix were done in https://github.com/stevenremot/cordova-brother-label-printer/commit/6dd9d11eb4d8596322d99c3e7dd84431ac11ce9f

stevenremot avatar May 20 '19 14:05 stevenremot

I succeeded in printing with the QL-820NWB in wifi infrastructure mode. I had to update the way the ip address was set though: https://github.com/stevenremot/cordova-brother-label-printer/commit/3585abc5fed56f8c68f027a71ba421a18c35bb58

stevenremot avatar May 20 '19 15:05 stevenremot

@stevenremot thanks for the updates.

yeah, this SDK is a bit tedious, and there's not a simple solution for every printer, it takes a little tweaking between models apparently.

we might be able to build out some scaffolding with the various configurations for each model, but we need testers to do that. :)

thanks for your help.

gordol avatar May 20 '19 17:05 gordol

@stevenremot pull requests are welcomed btw

gordol avatar May 20 '19 18:05 gordol

@stevenremot pull requests are welcomed btw

I'm totally willing to open a PR with my changes. However, my branch is based on this PR, so I wasn't sure about what to do... Should I open a PR to replace yours ?

stevenremot avatar May 21 '19 07:05 stevenremot

Hmm... can we merge into this one? Or are there conflicts... I haven't looked.

gordol avatar May 21 '19 18:05 gordol

There ya go, I merged it all in.

https://github.com/gordol/cordova-brother-label-printer/pull/45

gordol avatar May 21 '19 18:05 gordol

Yay thanks a lot!

stevenremot avatar May 22 '19 08:05 stevenremot

What do you need for this PR to be merged ? More testers ?

stevenremot avatar May 22 '19 08:05 stevenremot