university of nairobieie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/mobile... · i also...
TRANSCRIPT
![Page 1: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/1.jpg)
UNIVERSITY OF NAIROBI
FACULTY OF ENGINEERING
DEPARTMENT OF ELECTRICAL & INFORMATION ENGINEERING
MOBILE PHONE APPLICATION AND INTERFACE FOR A BAR CODE SCANNER
PROJECT INDEX: PRJ 025
PRESENTED BY
ACHIKI CORNELIUS MATONGO
F17/1752/2006
SUPERVISOR: DR. MWANGI MBUTHIA
EXAMINER: DR. G.S.O ODHIAMBO
PROJECT REPORT SUBMITTED IN PARTIAL FULFILMENT OF THE REQUIREMENT FOR
THE AWARD OF THE DEGREE
OF
BACHELOR OF SCIENCE IN ELECTRICAL AND ELECTRONIC ENGINEERING,
THE UNIVERSITY OF NAIROBI 2011
SUBMITTED ON: 18TH MAY 2011
![Page 2: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/2.jpg)
ii
DEDICATION
I dedicate this project to my family and friends
![Page 3: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/3.jpg)
iii
ACKNOWLEDGEMENTS
I would like to thank my family for the support they have offered to me while undertaking my studies
I would like to thank Dr. Mwangi Mbuthia, my supervisor for guiding me and providing necessary
support and ideas to aid in completion of this project.
I also appreciate the University of Nairobi, for creating a conducive environment for study and
research of this project.
I also express my gratitude to Muciiri Brian Roy Wambugu, Benjamin Ng’aru Kariuki and all my
friends for all the incite they provided me with and their advice during the period of doing the project.
![Page 4: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/4.jpg)
iv
DECLARATION AND CERTIFICATION
This is my original work and has not been presented for a degree award in this or any other university.
………………………………………..
ACHIKI CORNELIUS MATONGO
F17/1752/2006
This report has been submitted to the Department of Electrical and Information Engineering, The
University of Nairobi with my approval as supervisor:
………………………………
Dr. MWANGI MBUTHIA
![Page 5: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/5.jpg)
v
TABLE OF CONTENTS DEDICATION ..................................................................................................................................... ii ACKNOWLEDGEMENTS ................................................................................................................ iii DECLARATION AND CERTIFICATION .......................................................................................... iv ABSTRACT ..................................................................................................................................... viii 1 CHAPTER 1 ................................................................................................................................ 1
1.1 PROBLEM DEFINITION ....................................................................................... 1 1.2 OBJECTIVES ....................................................................................................... 1 1.3 PROJECT SCOPE ................................................................................................. 1
2 CHAPTER 2 ............................................................................................................................... 2 2.1 LITERATURE REVIEW ........................................................................................ 2
2.1.1 HISTORY OF ANDROID .................................................................................. 2 2.1.2 BARCODES .................................................................................................... 4 2.1.3 SYMBOLOGY ................................................................................................ 5
2.1.3.1 Discrete .................................................................................................... 6 2.1.3.2 Continuous ................................................................................................ 6
2.1.4 UPC ............................................................................................................... 7 2.1.4.1 UPC-version A .......................................................................................... 7
2.1.4.1.1 Calculating the Checksum......................................................................... 9 2.1.4.1.2 2-Digit Supplemental Codes for Periodicals ................................................. 9
2.1.4.2 UPC-version E ........................................................................................ 10 2.1.5 EAN ............................................................................................................. 11
2.1.5.1 EAN-13 .................................................................................................. 11 2.1.5.2 EAN-8 .................................................................................................... 12 2.1.5.3 PARITY ENCODING TABLE ..................................................................... 13 2.1.5.4 EAN CHARACTER SET ENCODING TABLE .............................................. 14
2.1.6 CODE 39 ...................................................................................................... 15 3 CHAPTER 3 .............................................................................................................................. 16
3.1 DESIGN AND IMPLEMENTATION ...................................................................... 16 3.2 THE USB IN BRIEF ............................................................................................ 16 3.3 USB IN MOBILE PHONES .................................................................................. 16 3.4 IMPLEMENTATION ........................................................................................... 17
3.4.1 DATABASE IMPLEMENTATION .................................................................... 17 3.4.1.1 PREVIEW OF SQLITE .............................................................................. 17
3.4.2 BARCODE IMPLEMENTATION...................................................................... 18 3.4.2.1 ENCODING OF THE BARCODE ............................................................... 18 3.4.2.2 DESIGNING THE DATABASE ................................................................... 21
3.4.2.2.1 Program algorithm ................................................................................ 22 4 CHAPTER 4 .............................................................................................................................. 24
4.1 RESULTS AND ANALYSIS .................................................................................. 24 5 CHAPTER 5 .............................................................................................................................. 27
5.1 CONCLUSION ................................................................................................... 27 5.2 FUTURE WORK................................................................................................. 27
REFERENCES .................................................................................................................................. 28
![Page 6: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/6.jpg)
vi
6 APPENDIX ................................................................................................................................ 29
![Page 7: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/7.jpg)
vii
LIST OF FIGURES Figure 2.1 Android System Architecture ............................................................................................... 3 Figure 2.2 UPC barcode ....................................................................................................................... 7 Figure 2.3 UPC-A Barcode................................................................................................................... 8 Figure 2.4 UPC-E Barcode ................................................................................................................. 10 Figure 2.5 EAN-13 Barcode ................................................................................................................ 11 Figure 2.6 EAN-8 Barcode ................................................................................................................. 13 Figure 2.7 Code 39 Symbol ................................................................................................................ 15 Figure 3.1 Check Digit Computation Flow Chart................................................................................ 20 Figure 3.2 Flow Diagram of The Scanning Process ............................................................................ 21 Figure 4.1 Initial Screen ..................................................................................................................... 24 Figure 4.2Barcode Scanner View ....................................................................................................... 24 Figure 4.3 Displayed image an d name ............................................................................................... 25
![Page 8: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/8.jpg)
viii
ABSTRACT
With the advancement in microprocessor technology, mobile phones are becoming more preferable in
our day to day lives as compared to personal computers since most phones are capable of
functionalities as sophisticated as our PC’s or laptops. Mobile phones nowadays have processor speeds
as high as 1Ghz and can have a storage capacity of about 32Gb and they also have long hours of battery
life.
In addition to these feature there is the aspect of great portability. When all this are combined into one,
the mobile phones can be viewed as a very powerful device that rival PC’s.
Hardware advancements also have made mobiles phones smaller and more efficient while including an
increasing number of peripherals.
![Page 9: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/9.jpg)
1
1 CHAPTER 1
1.1 PROBLEM DEFINITION
A mobile phone and a barcode scanner are to be interfaced such that a mobile phone application is to be
created and also an interface that will receive input from a barcode scanner and display item details
retrieved from a central database.
1.2 OBJECTIVES The study was aimed to achieve the following:
1. To develop a mobile application based on the android platform.
2. To develop a suitable means for the communication between the mobile phone and the barcode
scanner.
3. To develop a central database from which item details can be retrieved.
4. To understand the differences between a DTE (Data Terminal Equipment) and a DCE(Data
Communication Equipment).
5. To study and understand how the barcode system works including the basic principles of
operation of a barcode scanner.
1.3 PROJECT SCOPE The scope of this project is basically to make a mobile application and how to interface the mobile
phone to the scanner. The mobile application is to be developed in the Linux-based Android platform.
An algorithm based on the operation principles is also to be developed during the course of the project.
![Page 10: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/10.jpg)
2
2 CHAPTER 2
2.1 LITERATURE REVIEW
2.1.1 HISTORY OF ANDROID
In 2007, a group of handset manufacturers, wireless carriers, and software developers (notably, Google)
formed the Open Handset Alliance, with the goal of developing the next generation of wireless
platform. Unlike existing platforms, this new platform would be nonproprietary and based on open
standards, which would lead to lower development costs and increased profits. Mobile software
developers would also have unprecedented access to the handset features, allowing for greater
innovation.
There are already many mobile platforms on the market today, including Symbian, iOS, Windows
Mobile, BlackBerry, Java Mobile Edition (JME) but Android is the first complete, open, and free
mobile platform that was created by Google and the Open Handset Alliance(OHA). The other
platforms offer some access to the device hardware, but require writing complex C/C++ code and
making heavy use of proprietary APIs that are difficult to use. These proprietary operating systems that
often prioritize native applications over those created by third parties and restrict communication
among applications and native phone data.[1]
Android is built on top of a solid and proven linux kernel foundation. Linux provides the hardware
abstraction layer for Android, allowing Android to be ported to a wide variety of platforms in the
future. Internally, Android uses Linux for its memory management, process management, networking,
and other operating system services.
Android is designed not only for mobile phones but also for other hardware platforms.
![Page 11: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/11.jpg)
3
Android System Architecture.
Figure 2.1 Android System Architecture
• Linux Kernel
Core services (including hardware drivers, process and memory management, security, network, and
power management) are handled by a Linux 2.6 kernel. The kernel also provides an abstraction layer
between the hardware and the remainder of the stack.[3]
• Libraries
Running on top of the kernel, Android includes various C/C++ core libraries such as libc and SSL, as
well as:
a. Surface manager:-manages display
![Page 12: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/12.jpg)
4
b. Media codecs
c. SQL database
d. 2D and 3D graphics
e. Browser engine:-android uses the WebKit library.
• Android Runtime
This includes the Dalvik Virtual Machine and the core Java Libraries. Rather than use a traditional Java
virtual machine (VM) such as Java ME (Java Mobile Edition), Android uses its own custom VM
designed to ensure that multiple instances run efficiently on a single device.
The Dalvik VM executes Dalvik executable files, a format optimized to ensure minimal memory use.
• Android Framework
Android Application framework is a high-level layer to provide a developer with a space for a new
android applications development.
The main parts of the android framework are;
i. Activity Manager: This manages the life cycle of an activity
ii. Content Providers: This is the data that needs to be shared with other
applications in the phone.
iii. Resource Manager: This managers any part/resource that is not code.
iv. Notification Manager.
2.1.2 BARCODES Bar codes provide a simple and inexpensive method of encoding text information that is easily read by
inexpensive electronic readers. Bar coding also allows data to be collected rapidly and with extreme
accuracy.
Bar codes are usually made up of black bars and white bars in alternating sequence. The widths of
these black and white bars usually add up to a fixed width for all characters. This allows the complete
code to be scanned at any velocity within reasonable limits, because the timed widths of each bar can
be expressed as a fraction of the time to scan a complete digit. These fractions are relatively
independent of velocity provided the scan velocity does not change significantly in the course of a
scan.
Barcodes were originally developed and used in the US in the 1960’s by the railroad companies to
automatically identify their train wagons. In the early 1970s, common barcodes started appearing on
![Page 13: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/13.jpg)
5
grocery shelves. To automate the process of identifying grocery items, UPC barcodes were placed on
products.
Barcode system is almost a universal phenomenon when it comes to retail industry operations or any
other business where inventory management, employee record maintenance, asset tracking, etc are
automated using barcode technology.
This usually increases productivity and also reduces human error.
Some of the common uses of barcodes
1. Article numbering in supermarkets and other retailing operations.
2. Tracking of items in transit
3. Employee record maintenance
4. Patient identification
5. Library systems
6. Ticketing in sport centers, transport centers, entertainment joints etc.
7. Encoding of website URLs
8. Postal barcodes
Barcodes still remain the most reliable, inexpensive and easy to implement system of identification.
When compared to younger more functional auto ID technology such as RFID, there is a huge
difference in the hardware acquisition cost. A barcode is cheaper to generate since you can generate it
using pretty much any printer on the market and it can be read by cheap equipment. Most mobile
Enterprise phones these days can read barcodes simply using the built in camera along with a simple
piece of software.
RFID on the other hand, costs a lot more on average putting its fantastic functionality out of reach of
many projects for the time being.
2.1.3 SYMBOLOGY A bar code symbol is a parallel arrangement of varying width bars and spaces. Symbology is the term
used to describe the unambiguous rules specifying the way that data is encoded into the bar and space
widths. Each type of symbology (or barcode type) is a standard that defines the printed symbol and
![Page 14: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/14.jpg)
6
how a device, such as a barcode scanner, reads and decodes the printed symbol.
The specification of a symbology includes the encoding of the single digits/characters of the message
as well as the start and stop markers into bars and space, the size of the quiet zone required to be before
and after the barcode as well as the computation of a checksum.
Bar code symbologies can be categorized into two;
a. Discrete
b. Continuous
2.1.3.1 Discrete
Here each character can stand alone and can be decoded independently from the adjacent characters.
Each character is separated from its neighbor by loosely intercharacter gaps, which contain no
information. Every character has a bar on each end. In the decoding process, each character is treated
individually. Discrete barcodes make each character easier to find, but take up more space to print as
well. Discrete barcodes have higher tolerance for low print quality.
2.1.3.2 Continuous
The continuous barcode has no intercharacter gaps. Every character starts with a bar and ends with a
space or vice versa. Because of lack of intercharacter gaps, a continuous code requires less symbol
length to encode a given amount of data. Offsetting this density advantage is the fact that the range of
available demand printing technologies is more restricted for continuous codes than it is for discrete
codes.
Classification on Barcode Symbologies
1. Retail barcodes
These include; UPC-A, UPC-E, EAN-8 and EAN-13
2. Alpha-Numeric barcodes
These include; Code39,Code 93and Code 128
3. 2-Dimensional barcodes
Include; PDF417,Data Matrix, Code 49 and Maxicode.
![Page 15: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/15.jpg)
7
2.1.4 UPC UPC stands for Universal Product Code which is an American format for article numbering. A UPC
barcode contains 8 or 10 digits.
Figure 2.2 UPC barcode
Figure 2.2 shows a general structure of a UPC barcode. As we can see, the numbers below the barcode
are 811138000202. The digit 8 is the number-system character, the next five digits 11138 represent the
manufacturer’s number, the next five digits represent the product number and finally the last digit on
the right hand side of the barcode represents the check digit. The number-system character identifies
the symbol version and also the type of article. The check digit is used to detect errors. The check digit
and number-system character are not printed underneath the symbol.
The Universal Product Code (UPC) has been successfully employed in the supermarket industry since
1973.
There are two types of UPC barcodes namely;
a. UPC version A (UPC-A)
b. UPC version E (UPC-E)
UPC-A encodes 12-digits and is usually used for marketing products while UPC-E encodes 6-digits and
are usually associated with small packages.
2.1.4.1 UPC-version A
A typical UPC Version A symbol consists of two halves representing a total of 12 numeric digits. The
two six-digit halves are surrounded by left, centre and right guard patterns. The various guard bars can
![Page 16: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/16.jpg)
8
be thought of as start/stop patterns. The left half uses the odd parity encodations of digits, and the right
half uses the even parity encodations of digits.
Figure 2.3 UPC-A Barcode
As mentioned earlier the first numeric digit specifies the UPC number system digit. Here are some of
the various digits used for different specifications of products.
• 0- regular UPC codes
• 1- reserved
• 2- random weight items marked at the store
• 3- National Drug Code and National Health Related Items code
• 4- no format restrictions, for in-store use on non-food items
• 5- for use on coupons
• 6- reserved
• 7- regular UPC codes
• 8- reserved
• 9-reserved
The next group of 5 digits identifies the manufacturer (the manufacturer’s code). This number is
assigned by the Uniform Code Council (UCC). The first five digits of the right half of the pattern are
the product code digits and are assigned by the manufacturer, and the final digit is a Modulo 10
checksum check digit used for error detection. The check digit whose value is evaluated
mathematically based on all of the other numbers encoded in the symbol. A weighting scheme is used
in its calculation, so that the check digit also protects against transposition errors if the data is manually
entered. Although UPC is a continuous symbology the left and right halves of the pattern can be
independently decoded.
![Page 17: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/17.jpg)
9
2.1.4.1.1 Calculating the Checksum The checksum is a Modulo 10 calculation.
1. Add the values of the digits in positions 1, 3, 5, 7, 9, and 11.
2. Multiply this result by 3.
3. Add the values of the digits in positions 2, 4, 6, 8, and 10.
4. Sum the results of steps 2 and 3.
5. The check character is the smallest number which, when added to the result in step 4, produces
a multiple of 10.
Using the UPC code in figure 2.3 to calculate the checksum
Barcode data=12345678910
1. 1+3+5+7+9+0=25
2. 25*3=75
3. 2+4+6+8+1=21
4. 75+21=96
5. 96+X=100 therefore the check digit X=4
2.1.4.1.2 2-Digit Supplemental Codes for Periodicals
A UPC-A code may be augmented with a 2-digit or 5-digit extension. These extensions are handled as
separate barcodes and are generally used to create ISBN's (International Standard Book Numbers).
These extra digits are primarily used on periodicals and books.Weekly publications are generally
numbered 1-52, while semi-monthlies are numbered 1-24 and monthlies 1-12.
Because the bar height of either half of a UPC Version A symbol is greater than the width of the six
digits, omnidirectional scanning is possible if orthogonal scanning lines are employed. The scanner can
independently decode the right and left halves of the symbol because an examination of the data's
parity indicates which half was decoded. The guard bars are usually printed with greater length than
other bars in the symbol. This is done to maximize the allowable scanning tilt angle.
![Page 18: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/18.jpg)
10
2.1.4.2 UPC-version E
The UPC-E barcode is the short form representation of a UPC number. It reduces the data length from
12 digits to 6 digits by compressing the extra zeros. By suppressing zeroes, UPC-E codes can be
printed in a very small space and hence they are suited for identifying products in small packages. A
UPC-E barcode has 6 digits with an implied number system 0.
Figure 2.4 UPC-E Barcode
In addition to the requirement that the first digit of the barcode (number system) must be zero, there are
four rules that determine what UPC codes can be printed using the compressed UPC-E format:
1. If the last 3 digits of the manufacturer's number are 000, 100, or 200, the valid product code
numbers are 00000 - 00999 (1,000 numbers).
2. If the last 3 digits of the manufacturer's number are 300, 400, 500, 600, 700, 800, or 900, the
valid product code numbers are 00000 - 00099 (100 numbers).
3. If the last 2 digits in the manufacturer's number are 10, 20, 30, 40, 50, 60, 70, 80, or 90, the
valid product code numbers are 00000 - 00009 (10 numbers).
4. If the manufacturer's number does not end in zero, the valid product code numbers are 00005 -
00009 (5 numbers).
Like the UPC-A the UPC-E also has two versions, one can be augmented with a 2 digit supplement and
the other with a 5 digit supplement to the right of the barcode to increase the amount of information
encoded.
The six digits are enclosed between two left-hand guard bars and three right hand guard bars. A symbol
check character is encoded into the parity of the six data digits. Of the six digits, three have even parity
and three have odd parity
![Page 19: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/19.jpg)
11
2.1.5 EAN
EAN stands for the European Article Numbering and is a superset of UPC. This means that any
software or hardware capable of reading an EAN symbol will automatically be able to read an UPC
symbol. The only difference between EAN and UPC-A is that the number system code in UPC is a
single digit from 0 through 9 whereas an EAN number system code consists of two digits ranging from
00 through 99, which is essentially a country code. Each country has a numbering authority which
assigns manufacturer codes to companies within its jurisdiction. The manufacturer code is still five
digits long, as is the product code, and the check digit is calculated in exactly the same way.
EAN has two versions i.e EAN-13 which encodes 13 digits and EAN-8 which encodes 8 digits
2.1.5.1 EAN-13 EAN-13 is used world-wide for marking retail goods. The only difference between a UPC-A symbol
and an EAN-13 symbol is that the number system code is 2-digits long in EAN-13 as opposed to 1 digit
in UPC-A. Visually, the human-readable check digit is placed below the bar code instead of to the right
of it, but this does not make any difference, technically speaking, regarding the encoding itself.
Figure 2.5 EAN-13 Barcode
Just like a UPC-A the EAN-13 bar code is divided into four areas:
1. The number system,
2. The manufacturer code
3. The product code
4. The check digit.
![Page 20: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/20.jpg)
12
Normally the first number system digit is printed just to the left of the bar code, the second number
system digit is printed as the first character of the group of six numbers on the left-hand side below the
bar code, the manufacturer code is the next five digits on the left-hand side below the bar code, the
product code product code is the first five digits on the right-hand side below the bar code, and the
check digit is the last digit on the right-hand side below the bar code.
Before an EAN-13 symbol may be encoded, the software must compute the correct checksum digit
which will be appended to the bar code. The checksum digit is based on a modulo 10 calculation based
on the weighted sum of the values of each of the digits in the number system, manufacturer code, and
product code.
The steps for calculating the check digit are as follows:
1. Consider the right-most digit of the message to be in an "odd" position, and assign odd/even to
each character moving from right to left.
2. Sum the digits in all odd positions, and multiply the result by 3.
3. Sum the digits in all even positions.
4. Sum the totals calculated in steps 2 and 3.
5. The check digit is the number which, when added to the totals calculated in step 4, result in a
number evenly divisible by 10.
6. If the sum calculated in step 4 is evenly divisible by 10, the check digit is "0" (not 10).
2.1.5.2 EAN-8
EAN-8 is a shortened version of the EAN-13 code. An EAN-8 symbol has a left-hand guard pattern,
four odd parity digits, a centre guard pattern, four even parity digits, and a right-hand guard pattern. An
EAN-8 symbol encodes two flag digits (2-digit country code), five data digits, and one check digit.
![Page 21: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/21.jpg)
13
Figure 2.6 EAN-8 Barcode
UPC/EAN has proven to be extremely successful in the retail marketplace. In normal usage, every code
from a supermarket scanner is verified against an in store computer's database before being acted upon.
In this mode, very high data security has been reliably demonstrated.
2.1.5.3 PARITY ENCODING TABLE This table indicates the parity with which each character in the left-hand side of the bar code should be
encoded. The parity is based on the first digit of the EAN-13 value.
FIRST NUMBER
SYSTEM DIGIT PARITY TO ENCODE WITH
MANUFACTURER CODE
CHARACTERS
SECOND NUMBER SYSTEM
DIGIT
1 2 3 4 5
0(UPC-A) Odd Odd Odd Odd Odd Odd
1 Odd Odd Even Odd Even Even
2 Odd Odd Even Even Odd Even
3 Odd Odd Even Even Even Odd
4 Odd Even Odd Odd Even Even
5 Odd Even Even Odd Odd Even
6 Odd Even Even Even Odd Odd
7 Odd Even Odd Even Odd Even
8 Odd Even Odd Even Even Odd
9 Odd Even Even Odd Even Odd
Table 2.1 The Parity Encoding Table
![Page 22: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/22.jpg)
14
A UPC-A bar code always has a first number system digit of zero, and therefore uses exclusively odd
parity. In fact, any EAN-13 symbol which has a first number system digit of 0 is actually an UPC-A
symbol, not an EAN-13 symbol.
2.1.5.4 EAN CHARACTER SET ENCODING TABLE
This table indicates how to encode each digit of an EAN-13 bar code depending on which half (left or
right) of the bar code the digit is found in. In the case of a left-hand digit, the encoding (odd or even
parity) is based on the value of the first digit of the number system code
DIGIT LEFT HAND ENCODING RIGHT HAND
ENCODING ODD PARITY(A) EVEN PARITY(B)
0 0001101 0100111 1110010
1 0011001 0110011 1100110
2 0010011 0011011 1101100
3 0111101 0100001 1000010
4 0100011 0011101 1011100
5 0110001 0111001 1001110
6 0101111 0000101 1010000
7 0111011 0010001 1000100
8 0110111 0001001 1001000
9 0001011 0010111 1110100
Table 2.2 EAN CHARACTER SET ENCODING TABLE
The left hand encoding even parity is obtained as follows;
a. Changing all the zeros to ones and all the ones to zeroes in the odd parity column and then
reading them from right to left.
The right hand encoding is found by reading the left hand encoding parity in reverse.
![Page 23: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/23.jpg)
15
2.1.6 CODE 39
Code 39 was the first alphanumeric symbology to be developed. Code 39 is widely used in many
industries and is the standard for many government barcode specifications, including the U.S.
Department of Defense. Code 39 is defined in American National Standards Institute (ANSI) standard
It is a discrete, two widths, self checking, variable length symbology that can readily be printed by a
variety of technologies.
Every Code 39 character has five bars and four spaces. Of these nine elements, 3 are wide and 6 are
narrow.
A code 39 symbol comprises;
i. A leading quiet zone
ii. A start character
iii. Data characters
iv. Stop character
v. Trailing quiet zone
Figure 2.7 Code 39 Symbol
![Page 24: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/24.jpg)
16
3 CHAPTER 3
3.1 DESIGN AND IMPLEMENTATION
In the design, the android mobile phone is to be interfaced to the barcode scanner with the help of a
USB cable.
3.2 THE USB IN BRIEF
The USB was designed with the goal of being simple to use and low cost of implementation. The USB
was previously regarded as a high speed serial bus. Serial configuration was generally preferred as
compared to parallel configuration owing to cheap cables and easier mode of implementation.
The USB has the following features in relation to the PC;
a. Hot-pluggable:-I/O devices can be added to the PC while it is still running.
b. Easier to use:- The I/O devices is easily recognizable and the appropriate devices drivers
are configured automatically.
c. High Performance:-USB transfers at a rate of about 12Mbps which is much faster than
the existing serial and parallel ports.
d. Single connector type:-all devices are plugged into the same socket type
e. Power supplied by the cable:-most devices will not require extra external power source
to power them.
f. Power management:- the devices automatically turn off when not in use.
3.3 USB IN MOBILE PHONES
The mobile phone basically has to be converted into a host device so as to see the barcode scanner as a
peripheral and therefore the phone can retrieve whichever information the scanner acquires. The mobile
phone basically does not have enough power to drive the USB peripheral and thus an external source of
power for the USB would be required. Mobile phones with USB-host capabilities would be a major
milestone in the advancement in mobile technology since pretty much any device can be interfaced
with the mobile so long as it has a USB connector. Combining the extreme portability of the mobile
![Page 25: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/25.jpg)
17
phone and the versatility of the USB opens a wide range of applications.
The android platform also does not support USB-Host capabilities. Therefore, for the android phone to
support USB, drivers have to be written and patched to the Kernel of the phone. After this the android
kernel is then recompiled so as to integrate the USB drivers into the platform.
Some mobile phone manufactures have been able to add USB-host capabilities to their products for
example the Motorola DroidX, NEXUS 1 and Toshiba.
The possibilities for the interfacing of mobile phones and various peripherals are enormous and may
prove to be very useful in various fields.
For example a retailer might be able to request for more goods from a supplier by sending only the
codes of the goods he needs rather than writing a whole bunch of details relating to the goods he wants.
Since barcodes can be encoded with all the necessary information relating to a particular item. All the
retailer and the supplier need is a means to access a central database through the mobile phone and the
necessary services/orders are carried out.
Doctors may also be able to quickly reference a patient's details in a more efficient and fast way. This
can all be done if the mobile phone is able to access the records in a remote location.
3.4 IMPLEMENTATION In the implementation of the project, the Android SDK environment was used in the Eclipse platform.
For the creation of databases, SQLite was used.
3.4.1 DATABASE IMPLEMENTATION
3.4.1.1 PREVIEW OF SQLITE
SQLite is a relational database management system same as Oracle, IBM’s DB2 and Microsoft SQL
server. SQLite has a reputation of being extremely reliable and is the database system of choice for
many consumer electronic devices, including several MP3 players, the iPhone and the iPod Touch and
of course Android and Symbian phones.
![Page 26: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/26.jpg)
18
SQLite is commonly used because of these features;
a. It is Open-Source:-it is placed in the public domain.
b. It is lightweight and hence can be store within the memory allocation of the mobile phone;
c. It requires no setup or administration. There is no server, no config file and no need for a
database administrator unlike the standard SQL.
Lightweight and powerful, SQLite differs from many conventional database engines by using a loosely
typed approach to column definition. Rather than requiring column values to conform to a single type,
the values in each row for each column are individually typed. As a result, there’s no strict type
checking when assigning or extracting values from each column within a row.
3.4.2 BARCODE IMPLEMENTATION
For the mobile phone to be able to read and decode barcodes, a zXing(zebra crossing) library was used.
ZXing is an open-source, multi-format 1D/2D barcode image processing library implemented in Java.
It uses the built-in camera on mobile phones to photograph and decode barcodes on the device, without
communicating with a server.
ZXing supports several barcode formats i.e.; UPC-A and UPC-E, EAN-8 and EAN-13 ,Code 39 Code
93, Code 128 etc.
The zXing library can be called from within your application through an intent as shown;
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
3.4.2.1 ENCODING OF THE BARCODE
The zXing library encodes the barcode by considering that a “1” represents a bar or a dark section and
a “0” represents a "light" or "space" section of the bar code.
A double dark section will be viewed as a 1 1 and a double space or light section will be viewed as a
00.
Before the scanner encodes the value of the barcode, the checksum digit is firstly calculated and if it is
valid, the code is scanned else an error is returned i.e. the barcode is viewed as an invalid code. Validity
![Page 27: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/27.jpg)
19
of the checksum digit is such that the check digit (i.e. last digit of the barcode) is cross-referenced with
the value computed by the barcode scanner application. Therefore the two values have to tally/match
for a valid barcode.
Note;
Guard bars are usually encoded as dark-light-dark sections or bar-space-bars which can be viewed as
101. This applies for all the guard bars i.e. Left, Center and Right guard bars
Steps for encoding/decoding the barcode
1. Compute the checksum for validity
2. Check the number system digit value and cross-reference the respective odd-even parity
sequence with the parity encoding table.
3. Encode each number with the corresponding 1 0 sequence using the character set encoding
table taking into account the respective parity of the characters whether even or odd parity.
![Page 28: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/28.jpg)
20
Compute the Checksum
Start
Is computed check digit equal to check digit on
the barcode?
Read the barcode and determine the encoded data on the code
NO
YES
Figure 3.1 Check Digit Computation Flow Chart
![Page 29: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/29.jpg)
21
3.4.2.2 DESIGNING THE DATABASE
Figure 3.2 Flow Diagram of The Scanning Process
Start
Load the Database
Open the Scan Application
Scan the Barcode
Close the DB
End
Is the item reference by barcode in
DB?
Continue?
Display Image of the item
YES
NO
Yes
NO
NO
![Page 30: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/30.jpg)
22
3.4.2.2.1 Program algorithm
The program follows the following steps during its implementation; a. The scanning application is first called into action via an intent.
b. The symbology and barcode format are determined and the check digit is then confirmed for validity of the code.
c. Scanning is then initiated. d. The database is then queried.
e. The program then cross-references the bar code scanned to the codes in the barcodeId field in the database.
f. If the barcode code is found in the database the corresponding image and details are displayed.
g. The program then exits.
The database will have four columns and can be represented as shown in the snippet below;
private static final String DATABASE_NAME = "barcode.db"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_TABLE = "barcodes";
private static final String FIELD_ID = "_id"; private static final String BARCODE_ID = "BarcodesId"; private static final String PRODUCT_NAME = "Product"; private static final String PRODUCT_IMAGE = "Image";
private static final String DATABASE_CREATE = "create table barcodes (_id integer primary key autoincrement, "
+ "BarcodesId text not null, Product text not null, "
+ "Image_Path text not null);";
![Page 31: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/31.jpg)
23
After the creation of the database, the next step was to make the graphical user interface.
The GUI comprises of a scan button that is used to prompt for the opening of the barcode scanning
application. Firstly, the main layout is designed using XML (android uses XML for its graphical user
interface).
The button is then placed on the linear layout of the GUI and the button click functionality is the set as
follows.
scanButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub } });
The above code hooks up the Scan Button with the click functionality.
To navigate to the barcode scanning application we have to call the ZXing library via intents and
mentioned earlier.
Once the barcode has been detected and recorded, another function is performed to record the scanned
code on the main layout;
\ public void onActivityResult(int requestCode, int resultCode, Intent intent) { TextView tv1 = (TextView) findViewById(R.id.textView2); if (requestCode == 0) { if (resultCode == RESULT_OK) { contents = intent.getStringExtra("SCAN_RESULT"); format =
intent.getStringExtra("SCAN_RESULT_FORMAT");
TextView tv = (TextView) findViewById(R.id.textView2); tv.setText(contents);
![Page 32: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/32.jpg)
24
4 CHAPTER 4
4.1 RESULTS AND ANALYSIS
The following were the results that were observed when the application was run;
Figure 4.1 Initial Screen
Figure 4.2Barcode Scanner View
The default screen is as shown in figure 4.1 when the application is started. On clicking the “Scan
Barcode” button the view on figure 4.2 is shown. The red line is the one responsible for scanning the
barcode i.e the widths of the bars and spaces.
Once the barcode has been recognized and the value of the barcode determined, the product name and
the image of the product is displayed as shown in figure 4.3.
![Page 33: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/33.jpg)
25
Figure 4.3 Displayed image and name
![Page 34: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/34.jpg)
26
Figure 4.4 Database created
The graphical User Interface of the database that is created after scanning the barcode is as displayed in
Figure4.5
At the first instance of the scan, the barcode number that is displayed in Figure 4.3 is
inserted/appended into the BarcodesId field. The corresponding product name is also displayed in the
product field. For the image field, the path to where the camera stored the captured product image is
referenced.
This shows how the application displays in the event that the barcode scanned is not found in the
database.
![Page 35: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/35.jpg)
27
5 CHAPTER 5
5.1 CONCLUSION
The main objective of the project was to interface the mobile phone to a barcode scanner. In the project
an alternative method of scanning was introduced. This is because the android platform is a new
technology and does not currently support USB-hosting capabilities and thus the need to use an
alternative way of scanning whatever barcode we have.
Using the mobile phone camera the project was a success since a barcode could be scanned and
eventually retrieved from a central database as in the objective.
5.2 FUTURE WORK
Mobile phones will certainly be able to go into USB-host mode in future. This is however dependent on
the fact that mobile phone manufactures enable their handset to accept USB-host capability software or
integrate USB-host functionality within their proprietary software.
Upon achieving this, interfacing of mobile phones to the numerous peripheral devices would be
possible and the scope application of this feature would then be enormous.
![Page 36: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/36.jpg)
28
REFERENCES [1] Reto Meier , “Professional Android Application Development”, Copyright © 2009 by Wiley
Publishing, Inc., Indianapolis, Indiana
[2] Dr. G.S.O Odhiambo, “Database Management and Knowledgebase Systems Class Lecture
Notes” ,Department of Electrical and Electronics Engineering, 23rd March 2007.
[3] Ed Burnet, “Hello Android”, Published by Pragmatic BookShelf, Copyright © 2008 Ed
Burnette.
[4] http://www.gs1kenya.org
[5] http://en.wikipedia.org/wiki/Barcode
[6] IDAutomation ,“Barcodes For Beginners” , Copyright © 2000-2007 IDAutomation.com, Inc
[7] http://developer.android.com
[8] John Hyde, “USB Design by Example: A Practical guide to Building I/O Devices”, Intel
University Press
[9] Bruce Eckel, “Thinking in Java” , 3rd Edition, Copyright © 2003 by Bruce Eckel, President,
Mind View, Inc Published by Pearson Education, Inc.
[10] http://code.google.com/p/zxing/wiki/DeveloperNotes
![Page 37: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/37.jpg)
29
6 APPENDIX
barcodeApp.java package com.achiki.barcodeapp; import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.database.Cursor; import android.hardware.Camera; import android.hardware.Camera.PictureCallback; import android.hardware.Camera.ShutterCallback; import android.os.Bundle; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; import android.view.KeyEvent; import android.view.SurfaceView; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnKeyListener; public class barcodeApp extends Activity { /** Called when the activity is first created. */ String contents, format,p_duct; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button scanButton = (Button) findViewById(R.id.button1); TextView tv = (TextView) findViewById(R.id.textView1); ImageButton ib = (ImageButton) findViewById(R.id.imageButton1); SurfaceView surface = (SurfaceView) findViewById(R.id.surfaceView1); final EditText edittxt = (EditText) findViewById(R.id.editText1); // String uri = "/mnt/sdcard/DCIM/Camera/"; scanButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent( "com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "ONE_D_MODE");
![Page 38: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/38.jpg)
30
startActivityForResult(intent, 0); TextView tv = (TextView) findViewById(R.id.textView2); tv.setText(contents); // d.setContentView(vs); // d.show(); } }); edittxt.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { return true; } return false; } }); surface.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent pictureIntent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivity(pictureIntent); } }); } public void onActivityResult(int requestCode, int resultCode, Intent intent) { TextView tv1 = (TextView) findViewById(R.id.textView2); tv1.setText("hello world"); if (requestCode == 0) { if (resultCode == RESULT_OK) { contents = intent.getStringExtra("SCAN_RESULT");
![Page 39: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/39.jpg)
31
format = intent.getStringExtra("SCAN_RESULT_FORMAT"); final EditText edittxt = (EditText) findViewById(R.id.editText1); final String strTxt= new String(edittxt.getText().toString()); System.out.print(edittxt.getText().toString());
TextView tv = (TextView) findViewById(R.id.textView2);
tv.setText(contents); DBAdapter db = new DBAdapter(this); db.open(); long rowID; rowID = db.insertRow(contents, strTxt, "Image_Path"); System.out.println("rowid = " + rowID); db.close(); } else if (resultCode == RESULT_CANCELED) { // Handle cancel TextView tv = (TextView) findViewById(R.id.textView2); tv.setText("cancelled"); } } } }
![Page 40: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/40.jpg)
32
DBAdapter.java package com.achiki.barcodeapp; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.util.Log; import java.util.ArrayList; import java.util.List; public class DBAdapter { private static final String DATABASE_NAME = "barcode.db"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_TABLE = "barcodes"; private static final String FIELD_ID = "_id"; private static final String BARCODE_ID = "BarcodesId"; private static final String PRODUCT_NAME = "Product"; private static final String PRODUCT_IMAGE_PATH = "Image_Path"; private static final String TAG = "DBAdapter"; private Context context; private SQLiteDatabase db; private DatabaseHelper dbHelper; private static final String DATABASE_CREATE = "create table barcodes (_id integer primary key autoincrement, " + "BarcodesId text not null, Product text not null, " + "Image_Path text not null);"; public DBAdapter(Context ctx) { this.context = ctx; dbHelper = new DatabaseHelper(context); } private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); }
![Page 41: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/41.jpg)
33
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS barcodes");
onCreate(db); } } // open the database public DBAdapter open() throws SQLException { db = dbHelper.getWritableDatabase(); return this; } // close the database public void close() { dbHelper.close(); } // insert a row public long insertRow(String BarcodesId, String Product, String Image_Path) {
ContentValues initialValues = new ContentValues();
initialValues.put(BARCODE_ID, BarcodesId);
initialValues.put(PRODUCT_NAME, Product); initialValues.put(PRODUCT_IMAGE_PATH, Image_Path); return db.insert(DATABASE_TABLE, null, initialValues); } // delete a row public boolean deleteRow(long rowId) { return db.delete(DATABASE_TABLE, FIELD_ID + "=" + rowId, null) > 0; } public Cursor getRow(long rowId) throws SQLException { Cursor cursor = db.query(true, DATABASE_TABLE, new String[] { FIELD_ID, BARCODE_ID, PRODUCT_NAME, PRODUCT_IMAGE_PATH }, FIELD_ID + + rowId, null, null, null, null, null);
![Page 42: UNIVERSITY OF NAIROBIeie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/MOBILE... · I also appreciate the University of Nairobi, ... operation of a barcode scanner. 1.3 PROJECT](https://reader031.vdocuments.net/reader031/viewer/2022020303/5b7b1f517f8b9ae7368d1838/html5/thumbnails/42.jpg)
34
if (cursor != null) { cursor.moveToFirst(); } return cursor; }