在Android应用程序中嵌入ZXing [英] Embedding ZXing in android app

查看:185
本文介绍了在Android应用程序中嵌入ZXing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我也是一个不幸的Andr​​oid开发初学者谁需要有ZXing吧code扫描仪嵌在他的应用程序。

So I'm another unlucky android development beginner who needs to have ZXing barcode scanner embedded in his app.

有大量的问题,询问如何在这里做到这一点的计算器,但他们都没有一个答案是真正的理解和解释初学者。所有的答案说类似你所要做的就是建立ZXing项目的核心lib中,它引用您的项目,然后从ZXing的android /目录拷贝一些code到你的应用程序,你就大功告成了。但是,这不是一个菜鸟非常有帮助。

There is plenty of questions asking how to do this here on stackoverflow but none of them has an answer that is really understandable and explanatory for a beginner. All the answers say something like "all you have to do is build the core lib of ZXing project, reference it your project and then copy some code from the ZXing's android/directory to your app and you're done". But this is not very helpful for a noob.

我在我的项目ZXings核心库引用。我有律师code扫描仪的应用程序源代码开放。我想阅读和理解的吧code扫描仪应用程序中的code,但它是我的知识水平太复杂了。

I have ZXings core library referenced in my project. I have the Barcode Scanner app source open. I'm trying to read and understand the code of Barcode Scanner app but it is too complex for my level of knowledge.

我只是想在我的应用程序的一个按钮,当pressed,打开一间酒吧code扫描仪,扫描仪只能够扫描一个酒吧code,德code并返回我的数字,它并不需要任何地方发送code得到任何信息等,我带这些东西照顾自己。我只需要一个简单的扫描仪上按一下按钮启动,扫描code和给我的结果。但我不明白怎么做我自己。 我想这不应该是很难做到的,如果你只需要从ZXing扫描复制一些文字,你只需要了解其code。

I just want to have a button in my app that, when pressed, opens a barcode scanner, the scanner should only be able to scan a barcode, decode it and return me the numbers, it doesn't need to send the code anywhere to get any info etc, ill take care of these things myself. I just need a simple scanner that starts on button click, scans the code and gives me the result. But i can't figure how to do it myself. I assume this shouldn't be hard to do if you only need to copy some text from the ZXing scanner, you just need to understand its code.

因此​​,如果有人可以解释这个(告知复制其中code部位,如何启动一个按钮的onClick方法等扫描仪),请这样做,我敢肯定有很多人谁是真的很感谢这就像我会。

So if someone can explain this (tell which parts of code to copy, how to start the scanner in a buttons onClick method etc) please do so, I'm sure there's plenty of people who will be really thankful for this just as i will be.

推荐答案

我必须做什么,你被要求做的。这不是那么容易,但它也不错。这也是我的第一个(商业或其他方式)的Andr​​oid应用程序。 我所做的是:

I had to do exactly what you are being asked to do. It wasn't that easy, but it wasn't too bad either. It was also my very first (commercial or otherwise) Android app. What I did was:

  • 获得ZXing项目编译 和你的机器上运行。那里 是如何做到这一点的好教程<一href="http://stackoverflow.com/questions/4782543/solved-integration-zxing-library-directly-into-my-android-application">here.
  • 适应这一code,以满足您的需求。我剥夺了很多项目的客场只是基本的扫描仪。然后,我建我的周围项目的其余部分。以下是如何做到这一点。

  • Get the ZXing project compiled and running on your machine. There is a good tutorial on how to do this here.
  • Adapt this code to suit your needs. I stripped a lot of the project away to just the basic scanner. I then built the rest of my project around it. Here's how to do that.

适应核心的CaptureActivity要尽可能简单。所有你需要的是从核心扫描仪code返回的数字。这里是我的项目结构的画面:

Adapt the CaptureActivity in core to be as simple as possible. All you need is the number returned from the core scanner code. Here's a picture of the structure of my project:

  • 什么,你会发现,你需要修改4个文件的修改后的活动课工作。这些文件是CameraCaptureActivity类的CaptureActivityHandler类和德code螺纹和德code处理程序类。我主持这些文件这里

取这四个文件,并把它们放在你的ZXing工作项目的副本。取出原有的CaptureActivity和其他原始线程和处理程序类,您已经更换。 (忽略CaptureActivityHandlerDemo文件,因为它提出了有错误)

Take these four files and put them in a copy of your ZXing working project. Remove the original CaptureActivity and the other Original Threads and Handler Classes that you have replaced. (Ignore the CaptureActivityHandlerDemo file, as it was put up there by mistake)

更​​改包的名称以匹配工作ZXing包名。请确保您的活动被命名为在所有四个这些类的一样。这可能是通过在实现getHolder,而不是活动课本身的界面是一个好主意。

Change the package names to match the working ZXing package names. Make sure that your Activity is named the same in all four of these Classes. It might be a good idea to pass in an interface that implements "getHolder" rather than the Activity Class itself.

请确保您已更新的清单与任何更改活动名称。请确保您有导航到该活动的一种方式 - 也许使它在意图过滤器区域的默认类

Make sure you have updated your manifest with any changes to your Activity Name. Make sure you have a way of navigating to the activity - perhaps make it the default class in the intent filter area.

我已经包括了你的活动布局文件还 - 这是非常简单的,但它的所有您的需要来获取扫描仪和工作。这就是所谓的camera_capture.xml

I have included a layout file for your activity also - it's very simple, but it's all your need to get the scanner up and working. it's called camera_capture.xml

希望这是所有你需要起床和运行。这不是一个简单的过程,不幸的是我不能给你我的整个项目,因为它是一个商业化的产品。

Hopefully this is all you need to get up and running. It's not an easy process and unfortunately I can't give you my entire project as it's a commercial product.

GOOD LUCK !!

Good Luck!!

PS请张贴任何问题,因为对这个答案的意见,我会尽我所能来帮助。

PS please post any questions as comments on this answer and I'll do my best to help.

这篇关于在Android应用程序中嵌入ZXing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆