Showing posts with label android barcode scanner. Show all posts
Showing posts with label android barcode scanner. Show all posts

Wednesday, 20 June 2012

Integrating Zxing QR Code scanner Into your android Application | ZXing QR Reader | Android - Integrate ZXing QR code scanner


Hello Android Guys,

 Have you facing issue in Integrating QR Code scanner ?  

 Please follow this steps:

android qr code Step1 :Obtain the zxing source code
  Run this command from your terminal(for mac/linux os)
  svn checkout http://zxing.googlecode.com/svn/trunk/ 
  zxing-read-    only
  Also you can find the full source code at this url
  http://code.google.com/p/zxing/source/browse/trunk.               

 Step 2 : Build zxing core using Apache Ant
  You will need to build the core project into a jar file using apache ant
  (download from here http://ant.apache.org/ivy/download.cgi). 
  Using a shell or cmd prompt navigate to the root directory of 
  the downloaded zxing src and execute “ant -f core/build.xml”. 
  This will produce a file core/core.jar which
  we will use in the next step.   
  Download Core.jar from here

 Step 3: Build ZXing Android using Eclipse
  Create a New Android Project (File –> New –> Android Project).
  Set the project name to ZXing (or similar).
  Select the “Create project from existing source” radio button
  Click “Browse” and navigate to the android project that you downloaded from
  zxing  and click “OK” Select “Finish”

  The project will not currently build. We need to add the core.jar file (that we
  produced    in the previous step) into our project. Right-click on ZXing
  project –> properties –> Java Build Path –> Add External Jars –> Navigate to
  and select core.jar –> Open –> OK.

  Actually, while we’re here we should do one more very important thing!
  Right-click on ZXing project –> properties –> Android –> Scroll down and
  check/tick the “Is Library” checkbox –> OK

 Step 4: Include ZXing Android into your project.
   Within Eclipse,  Right-click on YOURPROJECTNAMEHERE project –>
   properties –>Android –> Scroll down to Libraries section –> Click Add –>
   Select ZXing (which should appear as an option as a result of completing
   previous step).


   Here ,I am sharing you a full running Sample code . Just download it, import
   it into your Eclipse and Run.

   1. AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.testqrcode"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TestQRCodeActivity"
            android:label="@string/app_name" >
            <intent-filter>
              <action android:name="android.intent.action.MAIN" />

              <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.google.zxing.client.android.CaptureActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden" >
            <intent-filter>
              <action android:name="android.intent.action.MAIN" />

              <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
              <action android:name="com.google.zxing.client.android.SCAN" />

              <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

  </manifest>
   2. TestQRCodeActivity.java
package com.testqrcode;

import com.google.zxing.client.android.CaptureActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class TestQRCodeActivity extends Activity {

 /** Called when the activity is first created. */
 Button b1;
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);
  b1 = (Button) findViewById(R.id.submit);

  b1.setOnClickListener(new OnClickListener() {
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Intent intent = new Intent(TestQRCodeActivity.this,
            CaptureActivity.class);
    // Intent intent = new
    // Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(intent, 0);
   }
  });
 }

 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  if (requestCode == 0) {
   if (resultCode == 1) {
    // Handle successful scan
    String capturedQrValue = intent.getStringExtra("RESULT");
    // String format =
    intent.getStringExtra("SCAN_RESULT_FORMAT");
          Toast.makeText(TestQRCodeActivity.this,
    "Scan Result:" + capturedQrValue, Toast.LENGTH_SHORT)
    .show();
   } else if (resultCode == RESULT_CANCELED) {
    // Handle cancel

   }
  } else {

  }
 }
}

 I am also sharing the screen shot which helps you in
        configuring the build path and zxing as a library  
         

 project.



        


android qr code reader integration
android qr code reader
qr code scanner
zxing qr code scanner
            
   
   May this will Helps you.
   Enjoy Coding…. J
   Cheers…. J

 

Copyright @ 2013 Android Developer Blog.