Java Android - 条码扫描,选项?志兴?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2607858/
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
Android - Barcode Scanning, Options? Zxing?
提问by Donal Rafferty
I want to create an application for Android that will be able to scan barcodes, get the information contained within the barcode and then be able to use that information in some way.
我想为 Android 创建一个应用程序,它将能够扫描条形码,获取条形码中包含的信息,然后能够以某种方式使用该信息。
I have no idea how to create a barcode scanner so I went Googling and it seems Zxing is the most commonly used way to implement a barcode scanner in an app.
我不知道如何创建条码扫描器,所以我去谷歌搜索,似乎 Zxing 是在应用程序中实现条码扫描器的最常用方法。
Some Links:
一些链接:
http://code.google.com/p/zxing/
http://code.google.com/p/zxing/
http://awalkingcity.com/blog/2008/08/25/qr-codes-made-easy-in-android/
http://awalkingcity.com/blog/2008/08/25/qr-codes-made-easy-in-android/
Using ZXing to create an android barcode scanning app
However the samples I found on zxing involved having to prompt the user to go to the market and install the zxing barcode scanner so that my app can then call the barcode scanner when its needed and the barcode scanner will then return the info to my app.
然而,我在 zxing 上找到的示例涉及必须提示用户去市场并安装 zxing 条码扫描器,以便我的应用程序可以在需要时调用条码扫描器,然后条码扫描器将信息返回给我的应用程序。
While this would be a good starting point for me I was wondering is there any other options that would allow me to have a barcode scanner embedded in my own application without having to prompt the user to download a secondary application?
虽然这对我来说是一个很好的起点,但我想知道是否还有其他选项可以让我在自己的应用程序中嵌入条形码扫描仪,而不必提示用户下载辅助应用程序?
采纳答案by Sean Owen
Developer here. I think you're going to want to just integrate via Intent in the end. You get the improvements, bug fixes, and platform-specific workarounds for free. It's much less code too. But I understand you're asking for an alternative.
开发人员在这里。我认为您最终只想通过 Intent 进行集成。您可以免费获得改进、错误修复和特定于平台的解决方法。它的代码也少得多。但我知道你在寻求替代方案。
You probably want to strip down Barcode Scanner (whose source is in android/ in the project) and strip out everything you don't need. That means leave only about the com.google.zxing.client.android
and com.google.zxing.client.android.camera
packages. The core decoding is in DecodeThread
, but the other code in these packages implements the little callback dance that does the continuous scanning and gets the usual scanning UI.
您可能想要剥离 Barcode Scanner(其源在项目中的 android/ 中)并去除您不需要的所有内容。这意味着只留下关于com.google.zxing.client.android
和com.google.zxing.client.android.camera
包。核心解码在 中DecodeThread
,但这些包中的其他代码实现了小回调舞蹈,它进行连续扫描并获得通常的扫描 UI。
If you embed the code you need to follow the terms of the Apache License.
如果您嵌入代码,则需要遵守Apache 许可条款。
回答by Chris K
Download and extend the Zxing "Barcode Scanner" app by adding your own code. It's under an Apache 2.0 License.
通过添加您自己的代码来下载并扩展 Zxing“条形码扫描仪”应用程序。它在 Apache 2.0 许可下。
回答by yanchenko
I'd suggest you use Zxing through intents and redirect to Android Market page ("market://details?id=com.google.zxing.client.android"
) if it's not there (catching ActivityNotFoundException
). Intents are great for inter-app communications like this.
我建议您通过意图使用 Zxing 并重定向到 Android Market 页面("market://details?id=com.google.zxing.client.android"
),如果它不存在(捕获ActivityNotFoundException
)。Intent 非常适合这样的应用间通信。
回答by Scott
Check out the new Google Play Services 7.8 API that includes Barcode tracking: https://developers.google.com/vision/barcodes-overview
查看包含条码跟踪的新 Google Play Services 7.8 API:https: //developers.google.com/vision/barcodes-overview
回答by formica
I have it working with this:
我有它的工作:
repositories { mavenCentral()
maven { url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/" }
}
compile 'com.google.zxing:core:3.2.1'
compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
I recommend using the IntentIntegrator
我建议使用 IntentIntegrator
IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.forSupportFragment(this).initiateScan();
The requestCode comes back with
requestCode 回来了
IntentIntegrator.REQUEST_CODE
No need to install a separate scanner
无需安装单独的扫描仪
回答by casillas
I recommend to use google barcode scan. It is pretty responsive. It is called Google Mobile Vision.
我建议使用谷歌条码扫描。它非常敏感。它被称为谷歌移动视觉。
The Barcode Scanner API detects barcodes in real time in any orientation. You can also detect and parse several barcodes in different formats at the same time.
Barcode Scanner API 实时检测任何方向的条码。您还可以同时检测和解析不同格式的多个条码。
https://developers.google.com/vision/
https://developers.google.com/vision/
https://codelabs.developers.google.com/codelabs/bar-codes/#0
https://codelabs.developers.google.com/codelabs/bar-codes/#0