Android Barcode Reading - Quick Start Guide
So what’s the easiest way to integrate barcode reading into your app?
Whilst it’s possible to integrate the Softek Barcode Reader into your Android app through our java class and jni library, it’s also possible to simply call our Bardecoder app direct from your own app with a minimal amount of work.
The following article describes how to call our Bardecoder Android app from your application, read a barcode and return the barcode value to your own app.
Step 1
Download the Bardecoder app to your phone from the Android Market:
https://market.android.com/details?id=com.softeksoftware.bardecoder
Step 2:
Add the following code to your project where you want to launch the Bardecoder app:
Intent myIntent; myIntent = new Intent(); myIntent.setComponent(new ComponentName("com.softeksoftware.bardecoder", "com.softeksoftware.bardecoder.scanner")); myIntent.putExtra("com.softeksoftware.bardecoder.scanner.settings", "MY XML SETTINGS - SEE BELOW"); myIntent.putExtra("com.softeksoftware.bardecoder.scanner.finishOnSuccess", true); myIntent.putExtra("com.softeksoftware.bardecoder.scanner.vibrateOnSuccess", true); myIntent.putExtra("com.softeksoftware.bardecoder.scanner.beepOnSuccess", true); myIntent.putExtra("com.softeksoftware.bardecoder.scanner.licenseKey", "MY LICENSE KEY - SEE BELOW"); try { startActivityForResult(myIntent, 0); } catch(ActivityNotFoundException ex) { bardecode.this.t.setText("Please install the Bardecoder app on your phone"); }
Step 3:
Add the following function to collect the results of the barcode scanning:
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (data != null)
{
Bundle bundle = data.getExtras();
// Get the value of the bar-code
// The bar-code type is also available in the key “com.softeksoftware.bardecoder.scanner.type”
value = bundle.getString(“com.softeksoftware.bardecoder.scanner.value”);
if (value != null)
{
// Do something with value
}
}
}
}
The XML settings allow you to control features of the barcode reader toolkit such as which barcodes to read. For example, if you want to read QRCodes and DataMatrix barcodes then include the following text in your settings string:
<ReadQRCode>1</ReadQRCode><ReadDataMatrix>1</ReadDataMatrix>
Example code:
myIntent.putExtra("com.softeksoftware.bardecoder.scanner.settings", "<ReadQRCode>1</ReadQRCode><ReadDataMatrix>1</ReadDataMatrix>");
Download the manual to get the full list of properties that can be set in this way.
You can get a free 30-day license key for the SDK by emailing sales@bardecode.com