如何在Android中使用ZXing

发布于 2024-12-24 16:11:31 字数 87 浏览 2 评论 0原文

我是 Zxing 的新手。我正在我的 Android 应用程序中使用 zxing 进行条形码转换。谁能指导我如何将 zxing 包含到 Android 设备中。

I am new to Zxing. I am doing barcode conversion using zxing in my android application. Can anyone guide me how to include zxing to android device.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

盛夏已如深秋| 2024-12-31 16:11:31

如果手机中安装了zxing条码扫描器,则非常简单:

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
       intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
       intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
       startActivityForResult(intent, 0);

OnActivityResult中:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                    String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
            } else 
            if (resultCode == RESULT_CANCELED) {
              // Handle cancel
            }
        }
    }

如果未安装:您可以将此代码放在try-catch块中并捕获异常,您可以这样做:

Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);

因此,它将应用程序重定向到android market,并且如果安装了条形码扫描仪,您的应用程序将继续运行一次。

如果你不想在你的应用程序中使用其他应用程序,你必须下载 zxing 库并尝试使用 core.jar 文件中的类(它是使用 apache ant 创建的)。按照本教程执行此操作:https://github.com/zxing/zxing/wiki/Getting-Started-Developing

所有 Intent 选项都可以在此处找到:

http://code.google。 com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java

If the zxing barcode scanner is installed in the mobile, its very easy:

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
       intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
       intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
       startActivityForResult(intent, 0);

and in OnActivityResult:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                    String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
            } else 
            if (resultCode == RESULT_CANCELED) {
              // Handle cancel
            }
        }
    }

If its not installed: u can put this code in try-catch block and catching the exception, u can do this:

Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);

So it redirects the app to android market and ur app continues running once if the barcode scanner is installed.

If u dont want to use the other app in ur app, U have to download zxing library and try using the classes from core.jar file(it is created using apache ant). Follow this tutorial to do that: https://github.com/zxing/zxing/wiki/Getting-Started-Developing

All Intent options can be found here:

http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java

攒眉千度 2024-12-31 16:11:31

您需要下载 Zing 的 .Jar 文件和添加到您的应用程序文件夹中。然后你可以调用classes &它的方法。

You need to download the Zing's .Jar file & add in to your application folder. Then you can call classes & methods of it.

≈。彩虹 2024-12-31 16:11:31

在 eclipse 中逐步设置 zxing 3.2.1

  1. 从“https 下载 zxing-master.zip ://github.com/zxing/zxing
  2. 解压zxing-master.zip,使用eclipse导入zxing-master中的“android”项目
  3. 从“http://repo1.maven.org/maven2/com/google/ zxing/core/3.2.1/"
  4. 在“android”项目中创建“libs”文件夹,并将 cor-3.2.1.jar 粘贴到 libs 文件夹中
  5. 点击项目:选择“属性”-> “Java编译器”将级别更改为1.7。然后点击“Android”将“Project build target”更改为android 4.4.2+,因为使用1.7需要使用Android 4.4编译
  6. 如果“zxing-master/android/app/src/main”中不存在“CameraConfigurationUtils.java” /java/com/google/zxing/client/android/camera/”。您可以从“zxing-master/android-core/src/main/java/com/google/zxing/client/android/camera/”复制它并粘贴到您的项目中。
  7. 清理并构建项目。如果您的项目显示有关“switch - case”的错误,您应该将其更改为“if - else”。
  8. 完全的。清理并构建项目

Step by step to setup zxing 3.2.1 in eclipse

  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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文