使用ZXing创造一个机器人吧code扫描的应用程序 [英] Using ZXing to create an android barcode scanning app

查看:180
本文介绍了使用ZXing创造一个机器人吧code扫描的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找如何将一杆code扫描仪添加到我的应用程序。有谁知道任何实例或不知道如何轻松地做到这一点?任何帮助是极大的AP preciated。

I've been searching on how to add a barcode scanner to my app. Does anybody know of any examples or know how to do this easily? Any help is greatly appreciated.

推荐答案

该ZXing项目提供了一个独立的酒吧code阅读器应用程序,它和mdash;通过Android的意图机制和mdash;可谁希望集成吧code扫描的其他应用程序调用。

The ZXing project provides a standalone barcode reader application which — via Android's intent mechanism — can be called by other applications who wish to integrate barcode scanning.

要做到这一点最简单的方法是调用ZXing 扫描 意图从您的应用程序,的这样的

The easiest way to do this is to call the ZXing SCAN Intent from your application, like this:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
    }
};

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

$ P $(如果没有安装ZXing或崩溃)pssing链接到 MSCAN 按钮将直接启动进入ZXing吧code扫描仪屏幕。一旦吧code已被确认,您将收到的结果在你的活动,这里的内容变量。

Pressing the button linked to mScan would launch directly into the ZXing barcode scanner screen (or crash if ZXing isn't installed). Once a barcode has been recognised, you'll receive the result in your Activity, here in the contents variable.

要避免崩溃,并简化了你的东西,ZXing有无<一href="https://github.com/zxing/zxing/blob/master/android-integration/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java"相对=nofollow>提供了一个实用工具类你可以将集成到应用程序,使ZXing流畅,通过将用户重定向到Android Market,如果他们没有它已经安装的安装。

To avoid the crashing and simplify things for you, ZXing have provided a utility class which you could integrate into your application to make the installation of ZXing smoother, by redirecting the user to the Android Market if they don't have it installed already.

最后,如果你想直接集成吧code扫描到您的应用程序,而依靠其安装在单独的ZXing应用程序,以及那么它是一个开源项目,你可以这样做! :)

Finally, if you want to integrate barcode scanning directly into your application without relying on having the separate ZXing application installed, well then it's an open source project and you can do so! :)

编辑:有人编本指南为这个答案(这听起来有点奇怪,我不能担保其准确性,我不知道为什么他们正在使用Eclipse在2015年):

Somebody edited this guide into this answer (it sounds a bit odd, I can't vouch as to its accuracy, and I'm not sure why they're using Eclipse in 2015):

一步一步设置zxing在Eclipse 3.2.1

  1. https://github.com/zxing/zxing 下载zxing-master.zip
  2. 解压缩zxing-master.zip,使用Eclipse导入机器人项目zxing主
  3. 下载核心3.2.1.jar从 HTTP ://repo1.maven.org/maven2/com/google/zxing/core/3.2.1/
  4. 创建库文件夹中的机器人项目,贴COR-3.2.1.jar到libs文件夹
  5. 单击项目:选择属性 - >Java编译器改变级到1.7。然后点击Android的变项目建设目标到Android 4.4.2+,因为使用1.7需要与Android 4.4
  6. 编译
  7. 如果CameraConfigurationUtils.java不中不存在zxing主/安卓/ APP / src目录/主/爪哇/ COM /谷歌/ zxing /客户/安卓/摄像头/。您可以复制zxing主/ Android的核心/ src目录/主/爪哇/ COM /谷歌/ zxing /客户/安卓/摄像头/并粘贴到您的项目。
  8. 清理并生成项目。如果你的项目显示错误关于开关 - 案,应该将其更改为如果 - 其他。
  9. 已完成。清理并生成项目。您可以点击企业的性质>安卓>点击是图书馆的使用为您的项目。
  1. Download zxing-master.zip from "https://github.com/zxing/zxing"
  2. Unzip zxing-master.zip, Use eclipse to import "android" project in zxing-master
  3. Download core-3.2.1.jar from "http://repo1.maven.org/maven2/com/google/zxing/core/3.2.1/"
  4. Create "libs" folder in "android" project and paste cor-3.2.1.jar into the libs folder
  5. Click on project: choose "properties" -> "Java Compiler" to change level to 1.7. Then click on "Android" change "Project build target" to android 4.4.2+, because using 1.7 requires compiling with Android 4.4
  6. If "CameraConfigurationUtils.java" don't exist in "zxing-master/android/app/src/main/java/com/google/zxing/client/android/camera/". You can copy it from "zxing-master/android-core/src/main/java/com/google/zxing/client/android/camera/" and paste to your project.
  7. Clean and build project. If your project show error about "switch - case", you should change them to "if - else".
  8. Completed. Clean and build project. You can click on "Proprties" > "Android" > click on "Is Libraries" to use for your project.

这篇关于使用ZXing创造一个机器人吧code扫描的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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