简体   繁体   中英

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. I am finding zxing's pretty good, but it does not offer any Object pascal translation.

  • Is it possible to compile the whole zxing project as a shared library, from which to call the barcode reader intent ?

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. Visit this git-hub repo https://github.com/dm77/barcodescanner

How to start: Add the following dependency to your build.gradle file.

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

or compile 'me.dm7.barcodescanner:zbar:1.7.2'

Then make a simpleScannerActivity and add this code.

  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. 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. 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.

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. Java code can not be compiled to an Android shared library with the existing Android development tools. 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

it can be compiled for 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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