6 Replies Latest reply on Dec 18, 2017 12:52 PM by Mark Piller

    Can't print over Bluetooth from Android to a ZD420 using ZSDK

    Colin Anderson

      Hi,

       

      I'm trying to print to a ZD420 label printer using Bluetooth from an Android app I am developing. I've been using the sample apps to guide me, but I can't get them to connect to the printer.

       

      The following code throws a ConnectionException:

       

      public class ZebraActivity extends AppCompatActivity {     @Override    protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);   setContentView(R.layout.activity_zebra);   String theBtMacAddress = "7C:EC:79:33:E3:89";   Context context = getApplicationContext();   sendZplOverBluetoothLe(theBtMacAddress, context);   }     private void sendZplOverBluetoothLe(final String theBtMacAddress, final Context context) {    new Thread(new Runnable() {    public void run() {   Connection thePrinterConn = null;    try {    // Instantiate connection for given Bluetooth® MAC Address.    thePrinterConn = new BluetoothConnectionInsecure(theBtMacAddress);     // Open the connection - physical connection is established here.    thePrinterConn.open();        // This example prints "This is a ZPL test." near the top of the label.    String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";     // Send the data to printer as a byte array.    thePrinterConn.write(zplData.getBytes());     // Make sure the data got to the printer before closing the connection    Thread.sleep(500);   } catch (Exception e) {    // Handle communications error here.    e.printStackTrace();   } finally {    // Close the connection to release resources.    if (null != thePrinterConn) {    try {   thePrinterConn.close();   } catch (ConnectionException e) {   e.printStackTrace();   }   }   }   }   }).start();   } }

      Results in Stacktrace:

      08-08 12:45:40.879 24427-24445/xxxW/System.err: com.zebra.sdk.comm.ConnectionException: Could not connect to device: read failed, socket might closed or timeout, read ret: -1

      08-08 12:45:40.879 24427-24445/xxx W/System.err:     at com.zebra.sdk.comm.ConnectionA.open(Unknown Source)

      08-08 12:45:40.879 24427-24445/xxx W/System.err:     at com.zebra.sdk.comm.BluetoothConnection.open(Unknown Source)

      08-08 12:45:40.879 24427-24445/xxxW/System.err:     at com.hermesinnovationlab.hermesreturns.zebra.ZebraActivity$1.run(ZebraActivity.java:41)

      08-08 12:45:40.879 24427-24445/xxx W/System.err:     at java.lang.Thread.run(Thread.java:818)

      08-08 12:45:40.879 24427-24445/xxx W/System.err: Caused by: com.zebra.sdk.comm.ConnectionException: read failed, socket might closed or timeout, read ret: -1

      08-08 12:45:40.879 24427-24445/xxx W/System.err:     at com.zebra.sdk.comm.internal.BluetoothInsecureZebraConnectorImpl.tryPublicApiWay(Unknown Source)

      08-08 12:45:40.879 24427-24445/xxx W/System.err:     at com.zebra.sdk.comm.internal.BluetoothInsecureZebraConnectorImpl.open(Unknown Source)

      08-08 12:45:40.879 24427-24445/xxx W/System.err: ... 4 more

       

      I'm running the app on a Samsung Galaxy A6 with Android 5.1.1.

      The manifest has the following permissions set:

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

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

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

       

      Can anyone offer me any advice as to how I can get this working? Event the Zebra sample app doesn't connect to the printer.

       

      Cheers,
      Colin.

        • Re: Can't print over Bluetooth from Android to a ZD420 using ZSDK
          Samantha Corn

          Hi Colin,

           

          By the Zebra sample app, do you mean the one packaged with the Link-OS SDK? The Zebra demo app is throwing this error as well? When you are trying to use the demo, is your device already paired to the printer?

          • Re: Can't print over Bluetooth from Android to a ZD420 using ZSDK
            Robin West

            Hi Colin,

            Your code looks fine.  I'm guessing you either have Bluetooth disabled on the printer, or the printer is BTLE only.  If you want me to check, reply with the full part number printed on the underside of the printer.  You can enable Bluetooth using the Printer Setup Utilities | Zebra app on PC or Android.  If the printer is BTLE, there is a separate Android BTLE library in the latest Link-OS SDK.

            • Re: Can't print over Bluetooth from Android to a ZD420 using ZSDK
              Mark Piller

              Is the ZSDK_ANDROID_BTLE_API.jar (library) still available? I cannot find it anywhere in the Zebra downloads. Also, ZSDK_ANDROID_API.jar (library) only has class files for Bluetooth and NOT Bluetooth low energy like the library I am attempting to locate.

               

              Thank you

                • Re: Can't print over Bluetooth from Android to a ZD420 using ZSDK
                  Mark Piller

                  For the benefit of all that may want or need to know where the library is for BTLE - here is the structure in your SDK installation:

                  C:.

                  ├───android

                  ├───android_btle

                  │   └───v2.12.3968

                  │       ├───demos

                  │       │   ├───androidstudio

                  │       │   └───src

                  │       │       └───com

                  │       │           └───zebra

                  │       │               └───android

                  │       │                   └───devdemo

                  │       │                       ├───connectivity

                  │       │                       ├───discovery

                  │       │                       ├───imageprint

                  │       │                       ├───listformats

                  │       │                       ├───multichannel

                  │       │                       ├───receipt

                  │       │                       ├───sendfile

                  │       │                       ├───status

                  │       │                       ├───statuschannel

                  │       │                       ├───storedformat

                  │       │                       └───util

                  │       ├───documentation

                  │       │   ├───com

                  │       │   │   └───zebra

                  │       │   │       └───sdk

                  │       │   │           ├───btleComm

                  │       │   │           │   └───class-use

                  │       │   │           ├───certificate

                  │       │   │           │   └───class-use

                  │       │   │           ├───comm

                  │       │   │           │   └───class-use

                  │       │   │           ├───device

                  │       │   │           │   └───class-use

                  │       │   │           ├───graphics

                  │       │   │           │   └───class-use

                  │       │   │           ├───printer

                  │       │   │           │   ├───class-use

                  │       │   │           │   └───discovery

                  │       │   │           │       └───class-use

                  │       │   │           ├───settings

                  │       │   │           │   └───class-use

                  │       │   │           └───weblink

                  │       │   │               └───class-use

                  │       │   └───resources

                  │       └───lib

                  ├───iOS

                  ├───PC

                  ├───PC-.NET

                  ├───PC-Card

                  ├───third_party

                  ├───Webservices

                  ├───windows_mobile_ce

                  └───xamarin