Sunteți pe pagina 1din 14

Getting Started with Android Development Zebra Android SDK

Java
Contents
Overview ............................................................................................................................................................................. 2
Target Audience ................................................................................................................................................................ 2
Feedback............................................................................................................................................................................. 2
System Prerequisites ....................................................................................................................................................... 3
Installations ......................................................................................................................................................................... 4
Creating Your First Zebra Mobile Application ............................................................................................................. 5
Deploying Your Mobile Application ............................................................................................................................. 13
See Also ............................................................................................................................................................................ 14




Overview
This document describes the end to end process of designing, packaging, deploying and running an Android application
using the ZebraLink
TM
Multiplatform SDK and Smartphone Utility.

The sample code used in this guide is from the Connecting Over IP and Bluetooth sample code article (SA137) which
is available for download to all registered members of the Zebra ISV Program here on the Zebra Support Portal.

For information on joining the ISV Program, contact a Program Manager in your area. Details here.

This file is available in a Chinese-language version here.


This file is available in a Spanish-language version here.
Este archivo esta disponible en Espaol - oprima aqu.

This file is available in a Portuguese-language version here.
Este ficheiro est disponvel na verso Portuguesa, clique aqui

Target Audience
The information delivered in this document assumes the reader has reasonable technical competence covering
Microsoft Windows, Java development with the Eclipse Integrated Development Environment (IDE), and core
programming concepts and rationales.
Feedback
We value all feedback. Please rate the article and then add your comments/suggestions in the text field that appears.


System Prerequisites
The following system prerequisites must be satisfied in order to complete this tutorial.

Java Development Kit (JDK) version 5 or 6
To develop Android applications, you need to install either version of the JDK.

To download the JDK, click here.

Eclipse version 3.5 (Galileo) IDE for Java Developers
Eclipse Galileo is the IDE used to develop Android applications such as the one featured in this whitepaper.

To download the IDE, click here.

ADT Plugin for Eclipse
The Android Development Tools (ADT) is a plugin for the Eclipse IDE that is designed to give you a powerful, integrated
environment in which to build Android applications.

For more information on installing the ADT plugin, click here.

Android SDK
The Android SDK is distributed free of charge by Google. It contains sample code, libraries, emulators and tools to help
you build applications for the Android platform.

For installation instructions, click here.

Zebra Multiplatform SDK
The Zebra Multiplatform SDK contains all the required components to develop applications for Zebra label printers. The
SDK includes a Java library (.jar) which provides the means to scan for, connect to and print on Zebra label printers.

For more information, including system prerequisites and download links for Zebra Multiplatform SDK, click here.

Zebra Network-Enabled Label Printer
In order to fully test the application created during the course of this tutorial, a network-enabled Zebra printer capable of
understanding ZPL or CPCL.

Bluetooth connectivity is available through the Zebra Multiplatform SDK and covered in other available tutorials.

For more information on Zebra label printers, click here.

Android Mobile Device
Whilst the Android Emulator included in the Android SDK satisfies most of the anticipated requirements for developing
Android applications, it is recommended that all development is fully tested against a physical device.


Note: For the list of printers and mobile devices that are supported by the Zebra Multiplatform SDK, click here.




Installations
All the items listed in the System Prerequisites must be installed. The default installation options for all these
prerequisites are satisfactory.


Creating Your First Zebra Mobile Application

You will be guided on how to create a mobile application that allows the handheld device to establish a Bluetooth or TCP
connection with a Zebra mobile printer.


1. Launch the Eclipse IDE. Enter your desired workspace path. For the purpose of this whitepaper, we shall use
c:\MyFirstZebraAndroidApp.





























2. Configure the SDK Location.
a. Go to Window -> Preferences.
b. Click Android on the left panel.
c. On the right panel, browse to the location of the Android SDK.
d. Click Apply. A list of SDK Targets should appear below.
e. Click OK to close the Preferences dialog.















3. Create an Android project.
a. Go to File -> New -> Android Project. Alternatively, you can go to File -> New -> Project, and select
Android -> Android Project.
b. Enter AndroidConnectAndPrint as the project name.
c. For Build Target, select Android 2.1-update1 with the corresponding API Level of 7.
d. Enter com.zebra.isv.connectAndPrint for both Application name and Package name.
e. Enter ConnectivityDemo next to Create Activity (it must be checked).
f. You may leave other default inputs unchanged
g. Click finish to close the New Android Project dialog and to create the Android project.




4. Design the GUI.
a. Define the variables and values that will be used in the layout (xml) files later.
i. In the Package Explorer, open strings.xml in the res/values folder
ii. Replace the contents of the String.xml file from the Strings.xml file from the Connecting Over
IP and Bluetooth sample code article (SA137).

Note: The source code used in this white paper is extracted from the Connecting Over IP and
Bluetooth sample code article (SA137) which is available for download to all registered
members of the Zebra ISV Program here on the Zebra Support Portal.

For information on joining the ISV Program, contact a Program Manager in your area. Details
here.

This source code defines the application name that shows up on the GUI, as well as the color
Red for the status bar background when no printer is connected. For more information on String
Resources, click here.

iii. Save and close the file.
b. Define the layout.
i. In the Package Explorer, expand the res/layout folder. Delete main.xml.
ii. In the same folder, create 2 files, connection_screen_with_status.xml and
connection_screen.xml.
iii. Replace the contents of the two files with the contents of the
connection_screen_with_status.xml and connection_screen.xml files from the Connecting
Over IP and Bluetooth sample code article (SA137).

connection_screen.xml defines a layout with elements for Bluetooth and TCP input.
connection_screen_with_status.xml is similar to the above, with the exception of an additional
connection status bar at the top.

For more information on Layout Resource, click here.
iv. Save and close the files.
c. Update the AndroidManifest.xml
i. Replace the contents of the AndroidManifest.xml file with the contents of the
AndroidManifest.xml file from the Connecting Over IP and Bluetooth sample code article
(SA137).

For more information on this file, click here.

5. Create Java helper classes.
a. Create a file DemoSleeper.java in the com.zebra.isv.connectAndPrint package and replace its
contents from the DemoSleeper.java file from the Connecting Over IP and Bluetooth sample code
article (SA137).

This file contains a static sleep method that will be used in ConnectivityDemo.java.

b. Create a file SettingsHelper.java in the com.zebra.isv.connectAndPrint package and replace its
contents from the SettingsHelper.java file from the Connecting Over IP and Bluetooth sample code
article (SA137).



This file contains methods used in ConnectivityDemo.java to persist Bluetooth and TCP settings for
subsequent recall.

6. Update ConnectivityDemo.java and include the Zebra Multiplatform SDK library for Android.
a. Replace the source code in ConnectivityDemo.java with the contents of the ConnectivityDemo.java file
from the Connecting Over IP and Bluetooth sample code article (SA137).

This class is the starting point of the Android application.

b. At this point, you should see many errors. To resolve the dependencies, right-click the
AndroidConnectAndPrint project, select Build Path, then Add External Archives.



c. Browse to the location of the ZSDK_API.jar file and click Open. The default installation path of this file
should be C:\Program Files\Zebra Technologies\zebralink_sdk\android\v1.0.317\ZSDK_API.jar.
d. The errors in ConnectivityDemo.java should disappear now.










7. Build and run the application.
a. Right-click the AndroidConnectAndPrint project, select Run As -> Android Application. This runs the
application in an Android emulator. The emulator might take a while to start up depending on the
available computer resources and hardware.




















b. To run the application, you need to unlock the screen on the emulator. To do this, drag the green lock
icon to the right of the screen.


















c. Congratulations. You now have your first Zebra mobile application running on an emulator! To exit the
application, simply click the back button on the emulator. To continue development, leave the emulator
running as it takes considerable amount of time to start up. Note that the Bluetooth and TCP connectivity
may not be correctly emulated. The application should be tested on a physical device, which will be
covered in the next section.
















Deploying Your Mobile Application

After your project is completed, it may be exported into an Android Application Package (.APK) file for deployment on an
Android Device.

1. Right-click the AndroidConnectAndPrint project, and select Export. On the Export dialog, expand Android,
select Export Android Application and click Next.

2. On the Export Android Application, enter the project in this case, it is AndroidConnectAndPrint and click
Next.

3. You will be asked to enter keystore information. If you do not have one, enter C:\AndroidKeyStore (or any other
desired folder) as Location, and then enter your desired password.

4. Fill up the Key Creation form and click Next. You must enter at least the Alias, Password, Confirm, Validity and
First and Last Name fields, failing which you will not be allowed to proceed. For more information on signing your
applications, click here.

5. On the Destination and key/certificate checks page, enter the path for the destination APK file. The folder that
you specify must first exist. If not, create it in windows explorer first.

6. Click Finish to export the project. Copy the .APK file to your device and install your application.




*Specifications subject to change without notice.
2009 ZIH Corp. EPL, APL, ZBI 2.0, ZBI-Developer, Element Energy Equalizer, E 3, ZebraLink, EPL2, ZebraNet, and all product names and numbers are Zebra trademarks, and Zebra, the Zebra head graphic
stripe, ZPL, ZebraNet, and ZPL II are registered trademarks of ZIH Corp. All rights reserved. Unicode is a trademark of Unicode, Inc. CG Triumvirate is a trademark of Agfa Division, Miles In c. IBM is a registered
trademark of International Business Machines Corporation. UFST is a trademark of Monotype Imaging Inc. a nd may be registered in certain jurisdictions. All other trademarks are the property of their respective
owners.
Corporate Headquarters Asia-Pacific Headquarters EMEA Headquarters Latin America Headquarters
+1 800 423 0442 +65 6858 0722 +44 (0)1628 556000 +1 847 955 2283
E-mail: inquiry4@zebra.com E-mail: apacchannelmarketing@zebra.com E-mail: mseurope@zebra.com E-mail: inquiry4@zebra.com

Other Locations
USA: California, Georgia, Rhode Island, Texas, Wisconsin Europe: France, Germany, Italy, Netherlands, Poland, Spain, Sweden Asia Pacific: Australia, China, Japan, South Korea
Latin America: Argentina, Brazil, Florida (USA), Mexico Africa/Middle East: India, Russia, South Africa, United Arab Emirates
GSA#: GS-35F-0268N
13919L-001 Rev. 9 (11/08)
See Also

For the list of printers and mobile devices that are supported by the ZebraLink Multiplatform SDK, click here.
For further ZebraLink SDK enabled Android Digital Device sample code and applications, refer to the Zebra
Support portal.
For information on ZebraLink Multiplatform SDK for Android Digital Devices, click here.
For further information on ZPL, see the ZPL Programming Guide on the Zebra website.
For further information on CPCL, see the CPCL Programming Guide of the Zebra website.

For any further information, sample code, white papers, and solutions or to request further content, visit the Zebra
Support portal.


Document Control
Version Date Description
1.0 2-Dec-10 Initial Release
1.1 1-Mar-11 Minor update to See also section
2.0 28-Jun-12 Updated Chinese link into document
3.0 31-July-12 Updated Spanish and Portuguese link into document

All links and information correct at time of writing
Created for the Zebra Global ISV Program by Zebra Development Services

S-ar putea să vă placă și