I am trying to Integrate ZXing QR Code into my android app without installing BarCode Scanner app, I have followed the steps as:
1) Firstly I have downloaded ZXing.zip file and extract it
2)open the ZXing project as an android existing project and then go to android folder and open the android folder and also include core.jar file into the ZXing project named CaptureActivity.
3)I have used the CaptureActivity project as a library in my project named 'QRCodeSample'. (Problem in including CaptureActivity as a library)
4)My code is as below3:
public class QRCodeSampleActivity extends Activity {
Button b1;
static String contents;
public static final int REQUEST_CODE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
/*Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE",
"QR_CODE_MODE");
startActivityForResult(intent, 0);*/
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 == RESULT_OK) {
contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.i("Barcode Result", contents);
Intent i1 = new Intent(QRCodeSampleActivity.this, webclass.class);
startActivity(i1);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("Barcode Result","Result canceled");
}
}
}
}
The manifest file is :
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
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>
<activity
android:label="@string/app_name"
android:name=".QRCodeSampleActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".webclass"></activity>
</application>
</manifest>
and its not adding library also
When I am trying to run my project,the error msg is:
Unable to instantiate activity ComponentInfo{com.qr.code/com.qr.code}: java.lang.ClassNotFoundException: com.qr.code in loader dalvik.system.PathClassLoader[/data/app/com.qr.code-1.apk]
After importing Zxing as existing project, Properties > Java Buildpath > Check "is library" (check button) and then try to add Zxing as library.
Make sure
webclass.class
exist in yourQRcodesampleActivity.java
For all those Android Studio/Gradle users out there
Okay guys, as my task today was to integrate ZXING into an Android application and there were no good sources for input all over, I will give you a hint what made my be successful - cause it turned out to be very easy (on version 2.*).
There is a real handy git repository that provides the zxing android library project as an AAR archive.
All you have to do is add this to your build.gradle
and Gradle does all the magic to compile the code and makes it accessible in your app.
To start the Scanner afterwards, use this class/method:
If you already visited the link you gonna see that i just copy&pasted the code from there the git readme. If not go there to get some more insight and code examples!
Hope to be helpful for future readers. Peace :)
MaterialBarcodeScanner: Easy to use barcode reader for your Android Project (Uses Google Mobile Vision API).
Provide gradle dependency
compile 'com.edwardvanraak:MaterialBarcodeScanner:0.0.6-ALPHA'
Build a MaterialBarcodeScanner
Hook it up to a button
Start scanning!
Step by step to setup zxing 3.2.1 in eclipse
I had the same Problem and after hours struggling with it I finally managed to solve it like this. as Rubiraj is pointing
*Right Click on your project > Properties > Android > (under tab library) Add the Zxing project *
Assuming you were able to correctly create Zxing project as a Library as it is explained here : http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/
Finally I got the answer,
As of ADT 14,the resource fields(such as R.id.decode) are no longer constants when defined in library projects
So in the ZXing library->android->com.google.zxing.client.android.CaptureActivityHandler.java and DecodeHandler.java
Replace both of these classes switch case statements with if-else,and then import this ZXing library into your project..
Rest of the coding of my own project is same...just the problem with the library classes as these are not updated as according to ADT 14..
Kanika