Android 安卓二维码扫描器库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20802586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:29:44  来源:igfitidea点击:

Android QRCode Scanner Library

androidqr-code

提问by Jay Snayder

What do we have out there available to us (if anything) that we can call for QR data discovery and extraction on an image?

我们有什么可用的(如果有的话)我们可以调用 QR 数据发现和图像提取?

While there have been plenty of posts thus far referencing the ZXing library for QRCode scanning, I haven't found that to be a solution that works for me. Several others have been asking for QRCode scanning alternatives and I have not seen useful feedback. I thought I might ask the community once more what the other options might be for a QR code library that does not launch an activity and call outside our own applications. It should scan images from the Camera2 API in a very simplistic manner. It shouldn't be a complicated library. I hadn't seen examples or individuals speaking of it in this manner.

虽然到目前为止已经有很多帖子引用了 ZXing 库进行 QRCode 扫描,但我还没有发现这是适合我的解决方案。其他几个人一直在要求提供 QRCode 扫描替代方案,但我没有看到有用的反馈。我想我可能会再次询问社区,对于不启动 Activity 和调用我们自己的应用程序之外的 QR 代码库,其他选项可能是什么。它应该以非常简单的方式从 Camera2 API 扫描图像。它不应该是一个复杂的库。我没有看到例子或个人以这种方式谈论它。

It actually puzzles me as to why there hasn't been native implementations of the QRCode functionality added into perhaps the Camera library or similar place within the Google SDK natively within the operating system.

它实际上让我感到困惑,为什么没有将 QRCode 功能的本机实现添加到相机库或操作系统中本机 Google SDK 中的类似位置。

Calling and requiring another application (or even requesting a download) is not an elegant solution and no users should be succumbed to doing such thing. As developers we should have access to a library capable of extracting a QRCode from an image or frame that we can then remove encoded data from.

调用并要求另一个应用程序(甚至请求下载)不是一个优雅的解决方案,任何用户都不应该屈服于做这样的事情。作为开发人员,我们应该可以访问一个能够从图像或帧中提取 QRCode 的库,然后我们可以从中删除编码数据。

采纳答案by Jay Snayder

While Sean Owen and others that have worked on the original Zxing library had provided an approach to work with the barcode libraries for the past several years, Google has finally put out an official release with Google Play Services for handling qr and barcodes.

虽然在过去几年里,Sean Owen 和其他人在原始 Zxing 库上工作提供了一种使用条形码库的方法,但谷歌终于发布了谷歌播放服务的官方版本,用于处理 qr 和条形码。

The barcode detection libraryis described here. The inclusion of these libraries will make for a smooth integration. I'll repost with some sample code for achieving these results from a captured image. At the moment, I wanted to update my answer for this official release. If this indeed does provide a nice way to get at this information (without jumping through hoops and complications), then I'll update with the source and check this off as an accepted answer.

条形码检测库,这里叙述。包含这些库将有助于顺利集成。我将重新发布一些示例代码,用于从捕获的图像中获得这些结果。目前,我想更新我对这个正式版本的回答。如果这确实提供了一种获取此信息的好方法(无需跳过箍和并发症),那么我将更新源并将其检查为已接受的答案。

The detection library that Google has provided within the past year has been a much easier library to work with. It allows for quick integration with the camera APIs and extracts the information with simplicity. This would be the component that I would suggest going forward with recognition. A quick snippet is demonstrated below for handling a Qr-code. A handful of pseudocode is left in there as well.

谷歌在过去一年提供的检测库是一个更容易使用的库。它允许与相机 API 快速集成并简单地提取信息。这将是我建议继续认可的组成部分。下面演示了一个用于处理 Qr 代码的快速片段。一些伪代码也留在那里。

public final void analyzeFrameForQrCode(byte[] qrCodePictureF, int imageFormatF, XriteSize previewWindowSizeF)
{
    if(!qrCodeDetectionPossible() || qrCodePictureF == null || mIsAnalyzingQrCodeFrame)
    {
        return;
    }

    ... //Bitmap conversion code

    Frame frame = new Frame.Builder().setBitmap(pictureTaken).build();
    SparseArray<Barcode> barcodes = mBarcodeDetector.detect(frame);
    if(barcodes != null && barcodes.size() != 0)
    {
        Barcode qrCode = barcodes.valueAt(0);//barcodes.get(Barcode.QR_CODE);
        if(qrCode != null)
        {
             if(extractInformationFromQrCode(qrCode.rawValue)) {
                    mIsRequestingBarcodeDetection = false;
                    vibrateForQrCodeDiscovery();
                    ((Activity)mContext).runOnUiThread(new Runnable() {
                        @Override
                        public void run()
                        {
                            hideBarcodeDetection(true);
                        }
                    });
                }
            }
        }

     ... //Cleanup and code beyond Qr related material

   } 
}

There are of course other calls available that can be taken advantage of. But there are really only a couple lines in there. The service for analyzing the frames with the library are not there by default on devices however. So, you should check whether or not the library is available (such as when internet is not available) before calculating as well. This is a slight nuisance of it. I had assumed it would be available as updates for devices going forward as part of the support library or Google Services going out to all devices. But it needs the communication first with an external service to use these library calls. Once it does this one time then that device is good from that moment on.

当然还有其他可用的调用可以利用。但那里真的只有几行。但是,默认情况下,设备上不存在用于使用库分析帧的服务。因此,您应该在计算之前检查图书馆是否可用(例如当互联网不可用时)。这是它的小麻烦。我原以为它将作为支持库或 Google 服务的一部分提供给所有设备的设备更新。但是它需要先与外部服务通信才能使用这些库调用。一旦它这样做了一次,那么该设备从那一刻起就很好了。

In my small example, I pop a toast up after a check and then back out of the activity and let the user check their connection. This can be done with a small amount of sample code as well.

在我的小例子中,我在检查后弹出一个祝酒词,然后退出活动并让用户检查他们的连接。这也可以通过少量示例代码来完成。

if(!mBarcodeDetector.isOperational())
{
    updateUserInstructions("The barcode library cannot be downloaded");
    return false;
}

Edit (Update):

编辑(更新):

A considerable amount of time has passed since working with the latest Google Play Services Vision libraries available for barcode detection. While the limitation for needing to download the library over the wifi is indeed a limitation, it is a one time process. And lets be honest...

自从使用可用于条码检测的最新 Google Play Services Vision 库以来,已经过去了相当长的一段时间。虽然需要通过 wifi 下载库的限制确实是一个限制,但它是一个一次性过程。老实说...

...our devices will have a connection. The library itself is downloaded in the background so you don't even notice it happening unless there is trouble downloading it and then you would have to report an appropriate corrective measure such as enabling a connection to the internet for it.

...我们的设备将有一个连接。库本身是在后台下载的,因此您甚至不会注意到它的发生,除非下载时遇到问题,然后您必须报告适当的纠正措施,例如为其启用与 Internet 的连接。

One additional tidbit is that it is a little tricky sometimes with how you integrate the library into your application. Using it as a library project worked on some devices and then failed on others. Adding the jar to the build path worked across a broader number of devices (it could be all, but it solved a problem). So as such, I would do it using the secondary method when including it in your projects for now.

另一个花絮是,有时将库集成到应用程序中的方式有​​点棘手。将其用作库项目在某些设备上工作,然后在其他设备上失败。将 jar 添加到构建路径适用于更广泛的设备(可能是全部,但它解决了一个问题)。因此,当我现在将它包含在您的项目中时,我会使用辅助方法来做到这一点。

回答by VivekTamilarasan

Android QRCode Scanner Library

安卓二维码扫描器库

This may help you, this library doesn't require any download or use of any external application. We can directly integrate this into your app and use it for scanning a QR code.

这可能对您有所帮助,该库不需要任何下载或使用任何外部应用程序。我们可以直接将其集成到您的应用程序中,并将其用于扫描二维码。

https://github.com/dm77/barcodescanner

https://github.com/dm77/barcodescanner

This wiki will help you to integrate with your app,

这个 wiki 将帮助您与您的应用程序集成,

https://github.com/dm77/barcodescanner/blob/master/README.md

https://github.com/dm77/barcodescanner/blob/master/README.md

回答by Nosakhare Belvi

You can also check MobileVisionBarcodeScanner(note I'm the author of this package). It is powered by Google's mobile vision API. Also see the overview here.

您还可以查看MobileVisionBarcodeScanner(注意我是这个包的作者)。它由 Google 的移动视觉 API 提供支持。另请参阅此处的概述 。

回答by Daniel S.

I used this library in my app. It also works with xing but you don't need any third party applications. Additional it's really easy to use.

我在我的应用程序中使用了这个库。它也适用于 xing,但您不需要任何第三方应用程序。另外它真的很容易使用。

https://github.com/journeyapps/zxing-android-embedded

https://github.com/journeyapps/zxing-android-embedded

Maybe you searched something like this.

也许你搜索过这样的东西。

回答by Sean Owen

You've already found the library you're looking for, I think. See the core/module:

我想你已经找到了你要找的图书馆。查看core/模块:

https://github.com/zxing/zxing/tree/master/core

https://github.com/zxing/zxing/tree/master/core

You're just looking at the Intent-based integration, but, in fact the core scanning is its own stand-alone library that you can embed into your own app.

您只是在查看Intent基于 -based 的集成,但实际上核心扫描是它自己的独立库,您可以将其嵌入到您自己的应用程序中。

I think Intent-based integration is best in most cases, simply because it is so simple, and, most people don't have the time to reimplement their own scanning UI and such on top of the core. Most devices have Barcode Scanner installed already, so it doesn't usually need a download.

我认为Intent在大多数情况下基于 -based 的集成是最好的,因为它非常简单,而且大多数人没有时间在核心之上重新实现他们自己的扫描 UI 等。大多数设备已经安装了 Barcode Scanner,因此通常不需要下载。

Still, take your pick. That's why there are at least two ways to use it.

不过,请自行选择。这就是为什么至少有两种方法可以使用它。

回答by Neel Mevada

Rather than QRCODE ZXing library integration You are able to open camera and scan QRCode from anywhere: The code i found below will may be helps to you for scanning QRCode :

而不是QRCODE ZXing库集成您可以从任何地方打开相机并扫描QRCode:我在下面找到的代码可能对您扫描QRCode有所帮助:

try {
                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
                startActivityForResult(intent, 0);
            } catch (Exception e) {    
                Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
                Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
                startActivity(marketIntent);
            }

Please remember that You must have a barcode scanner application by "Zxing" in Mobile Phone else it will firstly redirect to Google play store link for download it.

请记住,您必须在手机中通过“Zxing”安装条码扫描仪应用程序,否则它会首先重定向到 Google Play 商店链接进行下载。