简体   繁体   English

如何将Zxing条码扫描仪编译为共享库以在Android项目中使用?

[英]How to compile Zxing barcode scanner as a shared library to use in Android projects?

I am currently writing in Delphi XE7 for Android platform, but I really need a good and fast 2D barcode scanner. 我目前正在使用面向Android平台的Delphi XE7进行编写,但是我确实需要一台性能良好且快速的2D条形码扫描仪。 I am finding zxing's pretty good, but it does not offer any Object pascal translation. 我发现zxing很好,但是它不提供任何Object pascal转换。

  • Is it possible to compile the whole zxing project as a shared library, from which to call the barcode reader intent ? 是否可以将整个zxing项目编译为共享库,从中调用条形码阅读器的意图?

I think its wise to implement the bar code functionality in your app. 我认为在您的应用程序中实现条形码功能是明智的。 So I stumbled on this easy library. 所以我偶然发现了这个简单的库。 It seem like a union of zxing and zbar but much easier to interpret. 看起来好像zxing和zbar的结合,但更容易解释。 Visit this git-hub repo https://github.com/dm77/barcodescanner 访问此git-hub存储库https://github.com/dm77/barcodescanner

How to start: Add the following dependency to your build.gradle file. 如何开始:将以下依赖项添加到build.gradle文件中。

compile 'me.dm7.barcodescanner:zxing:1.7.2' 编译'me.dm7.barcodescanner:zxing:1.7.2'

or compile 'me.dm7.barcodescanner:zbar:1.7.2' 或编译'me.dm7.barcodescanner:zbar:1.7.2'

Then make a simpleScannerActivity and add this code. 然后进行一个simpleScannerActivity并添加此代码。

  public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    mScannerView = new ZXingScannerView(this);   // Programmatically initialize the scanner view
    setContentView(mScannerView);                // Set the scanner view as the content view
}

@Override
public void onResume() {
    super.onResume();
    mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
    mScannerView.startCamera();          // Start camera on resume
}

@Override
public void onPause() {
    super.onPause();
    mScannerView.stopCamera();           // Stop camera on pause
}

@Override
public void handleResult(Result rawResult) {
    // Do something with the result here
    Log.v(TAG, rawResult.getText()); // Prints scan results
    Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
}}

I know you're using Zxing but I'm here to recommend you the use of ZBar. 我知道您正在使用Zxing,但在这里向您推荐使用ZBar。 It works perfect. 完美的作品。

Here you have the only two classes you need to start working with it (Note one of those classes is a very useful example). 在这里,您只有两个类可以开始使用它(请注意,其中一个类是一个非常有用的示例)。 Also you'll need the libraries of ZBar (you need to put them into the libs folder of the app) and finally the JAR that you also will need. 另外,您还需要ZBar库(您需要将它们放入应用程序的libs文件夹中),最后还需要使用JAR。 And that's all. 就这样。 Happy coding. 快乐的编码。 All those files are here 所有这些文件都在这里

PS: Another alternative is not embed the Barcode Reader in your app and prompt the user to download a Barcode Reader app that you launch as an activity for result with an Intent and when it finishes it returns you the read barcode. PS:另一种选择是不将条形码阅读器嵌入您的应用程序中,并提示用户下载您作为活动启动的条形码阅读器应用程序,以获取具有意图的结果,并在完成后返回读取的条形码。

Is it possible to compile the whole zxing project as a shared library

The ZXing project is written in Java, the primary programming language for the Android platform. ZXing项目用Java编写,Java是Android平台的主要编程语言。 Java code can not be compiled to an Android shared library with the existing Android development tools. 无法使用现有的Android开发工具将Java代码编译为Android共享库。 So the answer is 'no'. 因此,答案是否定的。

Related questions: 相关问题:

there IS a delphi translation of the ZXing library here: https://github.com/Spelt/ZXing.Delphi/tree/v_3.0 这里 ZXing库的delphi转换: https : //github.com/Spelt/ZXing.Delphi/tree/v_3.0

it can be compiled for win32,win64,android, ios, osx. 可以针对win32,win64,android,ios,osx进行编译。

there is also a #define that can be used to compile it against VCL.Bitmap instead of FMX.Bitmap, depending on which framework you want to use 还有一个#define可用于根据VCL.Bitmap而不是FMX.Bitmap对其进行编译,具体取决于您要使用的框架

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

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