如何在Android上使用相机读取条形码?
我希望我的应用程序能够识别相机拍摄的条形码。可以使用Android SDK吗?
像这样的东西: 条码扫描仪
I want my application to recognize barcodes taken by camera. Is it possible using Android SDK?
Something like this:
Barcode Scanner
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
它没有内置于 SDK 中,但您可以使用 Zxing 库。它是免费、开源且获得 Apache 许可的。
2016 年建议使用条形码 API< /a>,它也可以离线工作。
It's not built into the SDK, but you can use the Zxing library. It's free, open source, and Apache-licensed.
The 2016 recommendation is to use the Barcode API, which also works offline.
2016 年更新
最新版本 Google Play 服务 v7.8,您可以访问新的 Mobile Vision API。这可能是现在实现条形码扫描最方便的方法,而且它还可以离线工作 。
来自 Android 条形码 API:
2016 update
With the latest release of Google Play Services, v7.8, you have access to the new Mobile Vision API. That's probably the most convenient way to implement barcode scanning now, and it also works offline.
From the Android Barcode API:
以下是使用相机 api
Activity_main.xml
build.gradle(Module:app)
的示例代码,在依赖项中添加 compile 'com.google.android.gms:play-services:7.8.+'
Here is sample code using camera api
activity_main.xml
build.gradle(Module:app)
add compile 'com.google.android.gms:play-services:7.8.+' in dependencies
这是示例代码:
我的应用程序使用 ZXing 条码扫描仪。
你需要这两个类:
IntentIntegrator 和
IntentResult
调用扫描仪(例如 OnClickListener、OnMenuItemSelected...)、“PRODUCT_MODE” - 它扫描标准一维条形码(您可以添加更多)。:
获取条形码结果:
内容保存条形码编号
Here is a sample code:
my app uses ZXing Barcode Scanner.
You need these 2 classes:
IntentIntegrator and
IntentResult
Call scanner (e.g. OnClickListener, OnMenuItemSelected...), "PRODUCT_MODE" - it scans standard 1D barcodes (you can add more).:
Get barcode as a result:
contents holds barcode number
您还可以使用 barcodefragmentlib,它是 zxing 的扩展,但提供条形码扫描作为片段库,因此可以非常容易地集成。
以下是有关库使用的支持文档
You can also use barcodefragmentlib which is an extension of zxing but provides barcode scanning as fragment library, so can be very easily integrated.
Here is the supporting documentation for usage of library
借助 Google Firebase ML Kit 的条形码扫描 API,您可以读取使用大多数标准条形码格式编码的数据。
https://firebase.google.com/docs/ml- kit/read-barcodes?authuser=0
您可以点击此链接来高效读取条形码。
With Google Firebase ML Kit's barcode scanning API, you can read data encoded using most standard barcode formats.
https://firebase.google.com/docs/ml-kit/read-barcodes?authuser=0
You can follow this link to read barcodes efficiently.
构建条形码扫描功能分为两部分,一是使用摄像头捕获条形码图像,二是从图像中提取条形码值。
可以使用相机应用程序从您的应用程序捕获条形码图像,并且可以使用 Firebase 机器学习套件条形码扫描 API 提取条形码值。
这是一个示例应用程序
https://www.zoftino.com/android-barcode-scanning-example
There are two parts in building barcode scanning feature, one capturing barcode image using camera and second extracting barcode value from the image.
Barcode image can be captured from your app using camera app and barcode value can be extracted using Firebase Machine Learning Kit barcode scanning API.
Here is an example app
https://www.zoftino.com/android-barcode-scanning-example
Firebase 条形码扫描 API 已弃用。
添加到您的 gradle(app)
了解更多详细信息,请查看此 官方指南
Firebase Barcode scanning API has been deprecated.
Add in your gradle(app)
for more details have a look on this official guideline
我对 parseActivityForResult 参数有疑问。我让它工作:
Latout for Activity:
I had an issue with the parseActivityForResult arguments. I got this to work:
Latyout for Activity: