Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Bluetooth support, SDK updates (testers needed) #42

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

gordol
Copy link
Owner

@gordol gordol commented Nov 9, 2018

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).

@koktaildotcom
Copy link

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: #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
Copy link

koktaildotcom commented Apr 2, 2019

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

@gordol
Copy link
Owner Author

gordol commented Apr 22, 2019

@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.

@koktaildotcom
Copy link

koktaildotcom commented Apr 23, 2019

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

@gordol
Copy link
Owner Author

gordol commented Apr 23, 2019

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

@koktaildotcom
Copy link

koktaildotcom commented Apr 24, 2019

@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.

.so files are not recognized by gradle / android when simply put in
the "libs/" folder. According to
https://stackoverflow.com/questions/24357687/how-to-include-so-library-in-android-studio,
this can be fixed by adding these files to the app/src/main/jniLibs
directory.
* Add a method "setLabelInfo" that can be used to configure the paper
  type. If no label type is configured, the print fails with
  "ERROR_WRONG_LABEL"
* Properly set printer's MAC address when connecting to the printer in
  bluetooth. The printer can't be found otherwise
@stevenremot
Copy link

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 stevenremot@088e14f. 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 stevenremot@6dd9d11

Properly set ipAddress in order for the SDK to be able to find the
printer on wifi infrastructure.
@stevenremot
Copy link

I succeeded in printing with the QL-820NWB in wifi infrastructure mode. I had to update the way the ip address was set though: stevenremot@3585abc

@gordol
Copy link
Owner Author

gordol commented May 20, 2019

@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
Copy link
Owner Author

gordol commented May 20, 2019

@stevenremot pull requests are welcomed btw

@stevenremot
Copy link

@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 ?

@gordol
Copy link
Owner Author

gordol commented May 21, 2019

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

@gordol
Copy link
Owner Author

gordol commented May 21, 2019

There ya go, I merged it all in.

#45

@stevenremot
Copy link

Yay thanks a lot!

@stevenremot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants