Android Question Zebra Printer

Discussion in 'Android Questions' started by RonkyOne, Mar 15, 2019.

Similar threads

B4A Library Printing and Pdf creation
B4A Library BLE 2 - Bluetooth Low Energy
B4A Library BLE Peripheral
B4A Question Classes are soon coming...
B4A Question Wordwrap to a canvas
  1. RonkyOne

    RonkyOne Member Licensed User

    Hi EREL ,
    can you Help me to translate this program to print on ZEBRA PRINTER bluetooth(BLE)

    I use example to search and connect zebra printer and it run ok.

    ref for ZEBRA

    writeStringToPrinter: function (str) {

       var that = this

       var maxChunk = 
    20 // Default is 20 bytes per write to characteristic

    if (app.getPlatform() == 'ios') {
         maxChunk = 300 // 300 bytes per write to characteristic works for iOS
    } else if (app.getPlatform() == 'android') {
         var maxChunk = 300 // Adjusting for Android     

       if (str.length <= maxChunk) {
       } else {
         // Need to partion the string and write one chunk at a time.
         var j = 0
         for (var i = 0; i < str.length; i += maxChunk) {
           if (i + maxChunk <= str.length) {
             var subStr = str.substring(i, i + maxChunk)
           } else {
             var subStr = str.substring(i, str.length)

           if (app.getPlatform() == 'ios') {
             writeStrToCharacteristic(subStr) // iOS doesn't need the delay during each write
           } else {
             // Android needs delay during each write.
             setTimeout(writeStrToCharacteristic, 250 * j, subStr) // Adjust the delay if needed

       function writeStrToCharacteristic (str) {
         // Convert str to ArrayBuff and write to printer
         let buffer = new ArrayBuffer(str.length)
         let dataView = new DataView(buffer)
         for (var i = 0; i < str.length; i++) {
           dataView.setUint8(i, str.charAt(i).charCodeAt())

         // Write buffer to printer
           serviceId: ZPRINTER_SERVICE_UUID,
           value: buffer,
           success: function (res) {
               title: 'Sent ZPL to printer successfully',
               icon: 'success',
               duration: 1000,
           fail: function (res) {
             console.log("ssi - Failed to send ZPL to printer:", res)
               title: 'Failed to send ZPL',
               icon: 'none',
               duration: 1000,
    thanks in advance
  2. DonManfred

    DonManfred Expert Licensed User

    Is this a B4A or a B4i question?
  3. RonkyOne

    RonkyOne Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    This is a community forum. You should not limit your questions or requests to a single member.
    Last edited: Mar 17, 2019
  5. DonManfred

    DonManfred Expert Licensed User

    There is missing a NOT ;-)
    Erel likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice