QR code scanner

别说谁变了你拦得住时间么 提交于 2019-11-27 14:10:43

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.

Andres Santiago

I 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.

Try zxing-android-embedded:

  • 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!

I did it using a set of plugins, plus I inserted my own additions to make it a 1-stop setup.

  1. unzip the attached zip file into your project ( https://github.com/chwagssd/qr/archive/master.zip )
  2. point to <script src="path/to/decoder.js"><script>
  3. Create a file input in your HTML page that has an id, say "xxx"

    <input type="file" id="xxxx">
    
  4. 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" id="xxxx">
    

I have setup a GIT repo here, grab the code (you can download the zip and put it in your javascript folder)

https://github.com/chwagssd/qr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!