How To Capture Data From Qr Scanner Using Zxing
Solution 1:
Using it via intent is the easiest way and it is possible to store the result of the scan, you'll just have to do it yourself. How it works is all in Zxing's docs at http://code.google.com/p/zxing/wiki/ScanningViaIntent
From the above link
First add code to invoke the Intent:
IntentIntegratorintegrator=newIntentIntegrator(yourActivity);
integrator.initiateScan();
Second, add this to your Activity to handle the result:
publicvoidonActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResultscanResult= IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result//here is where you would get the data from the scanResult//and store locally by writing to a file or however you //intend to store it
}
// else continue with any other code you need in the method
}
I haven't used this version Zxing, the one I used was at least 2 years ago but the process is the same
1 - start Zxing via Intent 2 - scan QR code 3 - retrieve the info from the scan in onActivityResult.
Solution 2:
Hi I have finally found an answer to this question. It was not that difficult as i thought (since Zxings code has been written by Zxing team and not by me.. anyway..)
So if you want to store the data captured by qr scanner(provided by Zxing) in your android code (for whatever purpose.. in my case i want to send this data to the web server.. anyway..) then you just need to modify the following function.. here is where you get the result of the scanned activity..
publicvoidhandleDecode(Result rawResult, Bitmap barcode) {
inactivityTimer.onActivity();
lastResult = rawResult;
Log.d("last result", "checking if raw result is what i expect");
System.out.println(lastResult);
ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);
historyManager.addHistoryItem(rawResult, resultHandler);
}
I have added Log and print statements to check if i am getting the correct result. and yes, it did give me a correct answer.. you can find this in CaptureActivity class.
@triggs: thanks for your help! You did get me on a right track :-)
Solution 3:
I chanced upon your thread searching for help with this set of code as well. In my case I had to send information back to the main application (ZXing is a library in my project - I know, I have talked to my clients about this but we were not able to use Intents due to business requirements).
Here is my solution if you need to pass information back to another activity from another project.
Project A is the main application, whereas the ZXing project will be called as such.
Edit handleDecode() in ZXing's CaptureActivity.java:
publicvoidhandleDecode(Result rawResult, Bitmap barcode) {
inactivityTimer.onActivity();
lastResult = rawResult;
ResultHandlerresultHandler= ResultHandlerFactory.makeResultHandler(this, rawResult);
if (source == IntentSource.NATIVE_APP_INTENT) {
IntentresultIntent=newIntent();
resultIntent.putExtra("result", rawResult.toString());
setResult(Activity.RESULT_OK, resultIntent);
finish();
}
}//end handleDecode()
And in your Project A's activity that is calling CaptureActivity,
@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent intent) {
NullQRCodeDialogFragmentdialog=newNullQRCodeDialogFragment();
Stringresult="";
if (resultCode == RESULT_OK) {
result = intent.getStringExtra("result");
if (result.equals(null)){
//TODO
} else {
//TODO
}
}//end onActivityResult
Hope this helps! This is my first post here and I'm so glad that I could contribute =)
Solution 4:
Here is the solution that I am using. It is working fine for me.
Intentintent=newIntent(SelectOptionActivity.this, CaptureActivity.class);
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
intent.setAction(Intents.Scan.ACTION);
startActivityForResult(intent, 1);
publicvoidonActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 1 && resultCode == RESULT_OK) {
finalStringcontents= intent.getStringExtra(Intents.Scan.RESULT);
finalStringformatName= intent.getStringExtra(Intents.Scan.RESULT_FORMAT);
}
}
Post a Comment for "How To Capture Data From Qr Scanner Using Zxing"