Android Barcode Generator Library Developer Guide

How to print barcodes in your Android applications?


Android Barcode is a Android barcode generator Java library (jar file) which generates and prints high quality 1D (linear) and 2D (matrix) barcodes in your Android applications


Index
 



Libraries required

 

Install Android Barcode Generator library


Install Android Barcode Generator library is an easy and simple job:

  • Add downloaded OnBarcode.AndroidBarcode.jar to your Android project classpath.

 

How to generate barcodes in your Android application?

The following Java code will explain how to use OnBarcode Android Barcode Generate library to print linear & 2D barcodes on your Android android.graphics.Canvas object.

private static void testCODE39(Canvas canvas) throws Exception
{
    Code39 barcode = new Code39();
    
    /*
       Code39 Valid data char set:
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (Digits)
            A - Z (Uppercase letters)
            - (Dash), $ (Dollar), % (Percentage), (Space), . (Point), / (Slash), + (Plus)
    
       Code39 extension Valid data char set:
            All ASCII 128 characters
    */
    // Code39 encodes upper case chars only, for lower case chars, use Code 39 extension
    barcode.setData("123456789012");
    
    barcode.setExtension(false);
    
    barcode.setAddCheckSum(true);
    
    // Code 39 Wide Narrow bar Ratio
    // Valid value is from 2.0 to 3.0 inclusive.
    barcode.setN(3.0f);
    // The space between 2 characters in code 39; This a multiple of X; The default is 1.;
    // Valid value is from 1.0 (inclusive) to 5.3 (exclusive)
    barcode.setI(1.0f);
    barcode.setShowStartStopInText(true);
    
    // Unit of Measure, pixel, cm, or inch
    barcode.setUom(IBarcode.UOM_PIXEL);
    // barcode bar module width (X) in pixel
    barcode.setX(1f);
    // barcode bar module height (Y) in pixel
    barcode.setY(75f);
    
    // barcode image margins
    barcode.setLeftMargin(10f);
    barcode.setRightMargin(10f);
    barcode.setTopMargin(10f);
    barcode.setBottomMargin(10f);
    
    // barcode image resolution in dpi
    barcode.setResolution(72);
    
    // disply barcode encoding data below the barcode
    barcode.setShowText(true);
    // barcode encoding data font style
    barcode.setTextFont(new AndroidFont("Arial", Typeface.NORMAL, 12));
    // space between barcode and barcode encoding data
    barcode.setTextMargin(6);
    barcode.setTextColor(AndroidColor.black);
    
    // barcode bar color and background color in Android device
    barcode.setForeColor(AndroidColor.black);
    barcode.setBackColor(AndroidColor.white);
    
    RectF bounds = new RectF(30, 30, 0, 0);
    barcode.drawBarcode(canvas, bounds);
    
    GeneratedBarcodeInfo barInfo = barcode.getBarcodeInfo();
}

To know more details about how to generate other barcode types in Android application, you look at the source code file AndroidBarcodeView.java in the trial package foler demo-src

 

Each barcode type properties settings in Android Barcode





OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.