I would like to create a QR code scanner in my app.
I went through the zxing ,but I could not understand it. I am interested in QR codes only.
All help is highly appreciated.
04 Answers
Place a copy of the com.google.zxing.client.* source packages into your project. You can start the zxing scanning activity like this:
Intent intent = new Intent(this, CaptureActivity.class);
startActivityForResult(intent, 0);In the same activity that you invoked the CaptureActivity in you can handle the result when the scan completes with the following onActivityResult method:
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { String response = data.getAction(); if(Pattern.matches("[0-9]{1,13}", response)) { // response is a UPC code, fetch product meta data // using Google Products API, Best Buy Remix, etc. } else { // QR codes - phone #, url, location, email, etc. Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(response)); startActivity(intent); } } } Hope this helps.
3I know this is an old question, but thought someone might find this useful.
I recently released a qr reader app, and ZXing really is the go-to library on Android. However, I found working with a copy of the source of ZXing project difficult. There is already a library that handles the ZXing core, and even optimizes it for custom usage.
- Super easy to add to your app.
- Takes care of opening camera in background thread for performance.
- Has docs/examples for custom usage of the scanner.
- Authors respond fast and commit once every 2 weeks :)
I put a guide on this post.
Hope this helps!
There is now an google API for that call Mobile vision.
Code sample:
I did it using a set of plugins, plus I inserted my own additions to make it a 1-stop setup.
- unzip the attached zip file into your project ( )
- point to <script src="path/to/decoder.js"><script>
Create a file input in your HTML page that has an id, say "xxx"
<input type="file">Then tell the page on load to QRIfy your field! Make sure to include your callback function, which will be called with a single argument (the FULL TEXT that was scanned): QRIfy('qrCode', onQrCode);//where qrCode is the id of your
<input type="file">
I have setup a GIT repo here, grab the code (you can download the zip and put it in your javascript folder)
1