QR code scanner

后端 未结 4 1330
醉话见心
醉话见心 2020-12-03 08:50

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 hi

4条回答
  •  一生所求
    2020-12-03 09:41

    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.

提交回复
热议问题