将条形码扫描仪添加到 Android 应用程序只是为了使用 Zxing 进行解码
我一直在寻找如何将条形码扫描仪添加到我的应用程序中以解码条形码。我发现了一个非常好的应用程序,我可以集成来执行称为“Zxing”的操作,但唯一的问题是,它具有编码和解码功能,但我真正想要的只是解码,以便我可以限制我从 Zxing 开源文件中使用的内容。
我找了很多地方都找不到只用zxing解码?
所以我的问题是我如何才能使用 Zxing 只进行解码而不同时进行编码? 示例代码和分步说明将非常感激。
感谢高级!
I've been searching on how to add a barcode scanner to my app just to decode barcodes. I found a really good application I could intergrate to do that called "Zxing" but the only problem is, it has encoding and decoding but what i really want is only decoding so that I could limit what I use from the Zxing open source file.
Ive searched plenty of places couldnt find just decoding with zxing?
So my question is how could I use Zxing only to decode and not to encode aswell?
Example codes and step by step instructions will be really appreciated.
Thanks in Advanced!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是通过 Intent 扫描。
这是一些示例代码:
然后在 onActivityResult() 中,您可以获取如下扫描数据:
编辑:
Intent 模型内置于 android 的核心思想中。它被放在那里是有充分理由的。通过仅使用 1 个应用程序来处理条形码扫描并将结果返回给任何其他想要使用它的应用程序,我们可以减少浪费的空间。
例如,如果用户有 5 个应用程序,它们都扫描不同的条形码并用它们执行各种操作,如果所有 5 个应用程序都在自己的应用程序中包含自己的条形码解码,则用户现在在其设备上拥有 5 个条形码读取功能副本浪费空间。
意图模型(特别是条形码解码)的另一个优点是它允许您的应用程序需要更少的权限。因为您不再需要使用相机。
它还使开发人员的一切变得更加简单。正如您在上面所看到的,通过 Intent 与 zxing 集成所需的工作量是最小的。您会发现可以重用 Zxing 项目的某些部分并将它们包含在您的应用程序中。但启动和运行要困难得多。
ZXing 项目是开源的,因此当然欢迎您开始浏览源代码来找出需要手动复制到项目中的类。我建议,如果您打算走这条路,那么在第一次尝试时不要尝试删除编码功能。让整个事情启动并工作,然后开始删除东西。如果您尝试仅采用项目的某些子集,则某些事情可能无法正常运行,即使它们看起来不应该受到您遗漏的内容的影响。
最后一点建议,我完全理解为什么你想在你自己的应用程序中包含此功能(我自己也去过那里)。但不要轻易做出这个决定,并且需要花一些时间考虑这样的事情:假设您确实在自己的应用程序中包含了此功能。暂时一切顺利。但过了一段时间后,您开始看到某些设备上弹出奇怪的错误,导致它们无法使用应用程序的扫描功能。现在,您将面临这样一种情况:您将不得不尝试调试和修复不是您创建的东西,并且可能不完全了解其幕后发生的所有事情。而与 Intents 的集成使得这种调试和修复是由那些真正了解它是如何工作的以及需要解决什么问题的人来完成的,并且他们按照自己的更新计划进行工作。因此,这些修复程序将比您发布的速度更快地传播给大众。
The simplest way to do it is scan via Intent.
here is some sample code:
Then in your onActivityResult() you can get the scanned data like this:
EDIT:
The Intent model is built in to the very core idea of android. And it was put there for good reason. By having only 1 application that handles the scanning of barcodes and just returns the result to any other application that wants to make use of it, we get less wasted space.
For instance, if a user has 5 apps that all scan different barcodes and do various things with them if all 5 of those apps include their own barcode decoding within their own app, the user now has 5 copies of the barcode reading functionality on their device wasting space.
Another upside to the Intent model(specifically with barcode decoding) is that it allows your application to require fewer permissions. Because you no longer need access to the camera.
It also makes everything much simpler for the developer. As you can see above the amount of effort it takes to integrate with zxing via intent is minimal. You'll find that it is possible to re-use some portions of the Zxing project and include them within your application. But that it is much more difficult to get up and running.
The ZXing project is open sourced so you are of course welcome to start picking through the source to figure out which classes you'll need to manually copy to your project. I suggest that if you intend to go this route that on your first attempt you do not try to remove the encoding functions. Get the entire thing up and working, and then start removing stuff. It is likely that if you try to take only some subset of the project some things won't function properly even though they don't seem like they should be affected by what you've left out.
One last bit of advice, I totally understand why you want to include this functionality within your own app(I've been there myself). But don't make this decision lightly and do take some time to consider things like this: Lets say you do include this functionality within your own application. All goes well for a while. But after some time goes by you start to see strange errors popping up on some devices that cause them to be unable to use the scanning functionality of your app. Now you will be in a situation where you are going to have to try to debug and fix something that you did not create, and likely do not completely understand all of what is going on under the hood of. Whereas integrating with Intents makes it so that this debugging and fixing is done by the people who actually know every bit of how it works and what problems need addressed, and they work on their own update schedule. So this fixes will get out to the masses much quicker than you could probably get them out.