简体   繁体   English

如何在android应用程序中导入ZXING库?

[英]how to import ZXING library in android application?

I need to implement ZXING QR code scanner in my application. 我需要在我的应用程序中实现ZXING QR代码扫描程序。 I have complete source code for ZXING Android. 我有完整的ZXING Android源代码。 Now, I want to use this in my application. 现在,我想在我的应用程序中使用它。 my question is that should I copy all ZXING library code in my application including manifest,xml and java files or I can have a jar file which I need to just add in my application? 我的问题是,我应该在我的应用程序中复制所有ZXING库代码,包括清单,xml和java文件,或者我可以有一个jar文件,我需要在我的应用程序中添加它? Can anybody tell me how to create jar file from android code, or is any ZXING jar already available which I can just include in my application? 任何人都可以告诉我如何从Android代码创建jar文件,或者任何ZXING jar已经可用,我可以在我的应用程序中包含它?

http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/ http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/

Thats a step by step guide to natively integrating. 这是本地集成的一步一步指南。 It integrates the zxing project into yours as a backup of sorts. 它将zxing项目整合到您的项目中作为各种备份。 You will send out an intent request, but your application is registered as a receiver of that request. 您将发出意向请求,但您的应用程序已注册为该请求的接收方。 If the user doesn't have a different scanner, yours will be the only option. 如果用户没有不同的扫描仪,那么您的扫描仪将是唯一的选择。 If they have other scanners it will allow the user to choose. 如果他们有其他扫描仪,它将允许用户选择。 If you want your app to always be chosen without another option, the comments in the tutorial detail how to change the intent filter to do it. 如果您希望始终在没有其他选项的情况下选择应用程序,则教程中的注释将详细说明如何更改意图过滤器以执行此操作。

Keep in mind this is the quick and dirty way to do it. 请记住,这是快速而肮脏的方式。 As others have mentioned, ZXing provides a great tutorial on how to send a barcode intent out and point them to the market if they don't have a scanner. 正如其他人所提到的,ZXing提供了一个很好的教程,介绍如何发送条形码意图,如果他们没有扫描仪,则将它们指向市场。

In Zing library you only need the android/ and the core/ projects . 在Zing库中,您只需要android/core/ projects ZXING library code doesn't have core.jar file. ZXING library代码没有core.jar文件。 You have to create core.jar file manually from the command line only (can be a ​bit tricky) so download core.jar alone from this link 你必须core.jar file manually from the command line创建core.jar file manually from the command line (可能有点棘手)所以从这个链接download core.jar alone

core.3.2.0 download core.3.2.0下载

then need to add the core.jar file into our project. 然后需要将core.jar文件添加到我们的项目中。

add this dependency in app level gradle app level gradle添加此依赖app level gradle

'com.google.zxing:core:3.2.0' 'com.google.zxing:核心:3.2.0'

REFERENCE site 参考网站

Integrate zxing barcode 集成zxing条码

QR code using ZXing library QR码使用ZXing库

If all you need to do is scan a barcode...then you can simply do it via intents. 如果你需要做的只是扫描一个条形码......那么你可以通过意图来完成它。 Check this page for a tutorial on scanning via intents. 查看页面以获取有关通过意图扫描的教程。

There is a project in github which was embedded in an android application and it is compatible as android studio project; github中有一个项目嵌入在Android应用程序中,它与android studio项目兼容;

https://github.com/journeyapps/zxing-android-embedded https://github.com/journeyapps/zxing-android-embedded

If you live a problem about gradle when you run above project, you can use below project which is same project but there is not any issue about gradle file; 如果你在上面的项目运行时遇到gradle的问题,你可以使用同一个项目下面的项目但是gradle文件没有任何问题;

https://bitbucket.org/_oguzhan/ocrandroid https://bitbucket.org/_oguzhan/ocrandroid

You would never want to copy the android/ code completely. 你永远不会想要完全复制android/代码。 If anything, you want to compile the core/ code, and place the resulting core.jar in your project's libs/ folder. 如果有的话,你想编译core/代码,并将生成的core.jar放在项目的libs/文件夹中。 Then, you have access to the core scanning code in your project. 然后,您可以访问项目中的核心扫描代码。

But, it is far easier to integrate via Intent as Archit says. 但是,正如Archit所说,通过Intent进行集成要容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM