Delphi Android integrates Google ZXing (call jar file)

Source: Internet
Author: User

The previous article introduced in the Delphi app (hereinafter referred to as the app) can use intent to call Google ZXing Barcode Scanner (hereinafter referred to as ZX), its advantages and disadvantages, the advantage is that we do not need to focus on the details of ZX itself, just call its interface, The disadvantage is the need to install the ZX scanner, so that the customer experience is not good enough, then can be directly integrated into the application of ZX, the answer is yes, but the actual operation will be slightly cumbersome, we specifically look at the process, which is divided into two parts: The first part describes how to configure the compilation ZX source code, The second section describes how to integrate with apps.

the first part: ZX Source configuration and compilation1: Download the source code

I chose 2.3.0 version, download after decompression such as:

We only need to use three folders, where

Core: Kernel library file.

Android-integration: The integrated library that comes with it, which is used at compile time.

Android: Comes with a sample scanner (ZX).

2. Packaging the core library as a jar

Here I first to the core and Android-integratio separately packaged into jars to use, you can also directly use the source code. Open Eclipse, new Android Application project, name can be taken, do not need to create activity, after the completion of the new SRC folder under the project, the core of the COM folder is copied into SRC, right-click the project, select Export, In the window, select the Jar file in Java:

Select only the SRC folder, where the export named Zxcore2.3.jar,android-integratio does the same operation and gets Zxintegration2.3.jar to stay.

3. Compiling ZX

Copy an Android folder (name can be picked up), open Eclipse, create Android from existing code, select the above folder, complete the project will have Captureactivity (ZX), Then import the two jar files packaged above, as shown in:

Build, and if there are no error hints, the environment is already configured successfully.

4. The source code changes slightly, so that Delphi can properly callback

A. Open the Captureactivity.java, comment out the Oncreateoptionsmenu event, and temporarily hide the menu so that it looks more like a module (you can also keep it, However, the resource files for the relevant features must be published and the appropriate activity (as related) should be added to the androidmanifest.

B. Navigate to the Onresume event: note the following two blocks of code:

Now it's time to build or run the project again and wait for the app to integrate.

Part Two app integration ZX

1. Integrating resources

To create a new Firemonkey Mobile App, create the following folder in the root directory:

Copy the files in res in captureactivity to Capture_assets (in this case the Capture_assets folder is a few help files, not used, can be deleted).

2. Create a local callback function

Create Nativeactivitysubclass.java, which is used to callback the Onactivityresult event after ZX completes the scan, which inherits from the Delphi Nativeactivity and registers a native callback method inside, which will Nativeactivitysubclass.java the detailed process of generating nativeactivitysubclass.dex will not repeat, here is the general process, the first to bring the Delphi Classes.dex Revert to Embarcadero.jar, use Javac with Embarcadero.jar and Android.jar Environment compilation Nativeactivitysubclass.java get Nativeactivitysubclass.class, use jar CVF command Package the nativeactivitysubclass.class into a jar and use the DX to generate the Nativeactivitysubclass.dex.

3. Merging Dex

There are 3 files to merge, Delphi's Classes.dex, Nativeactivitysubclass.dex, and a bin\ in the Captureactivity project. Classes.dex, using Dexmerger to merge the above 3 Dex as a classes.dex, this function has been integrated.

4. Add Permissions

Delphi IDE > Project > Options > Uses permission Add permissions in the following:

5. Modify AndroidManifest.template.xml

A: Change the default name to [package]. [Nativeactivitysubclass] (Depends on your name);

B. Add captureactivity (only the scan function is added here, others can be added as needed).

6. Release

A. Project > Deployment:

Package Capture_res in the directory (not all the files will be packaged in, I deleted some multilingual and help files (if your local language is not Simplified Chinese, you can add it yourself);

B. Replace the Delphi Classes.dex with the integrated Classes.dex.

7. Build APP, call ZX

Since ZX has been integrated, the call is very simple, just three lines of code (detailed call to the visible demo):

[Delphi]View PlainCopy
    1. Procedure callinternalzxing;
    2. Var
    3. Lintent:jintent;
    4. Begin
    5. Lintent: = Tjintent.  Javaclass. Init;
    6. Lintentsetclassname (Sharedactivitycontext, stringtojstring ('  Com.google.zxing.client.android.CaptureActivity '));
    7. Sharedactivity. Startactivityforresult (Lintent, 0);
    8. End

App Run (note that the original "barcode scanner" has become our app name):

Returns the encoding format and parsing result:

Complete examples (including ZXing2.3 source code, modified version captureactivity and detailed demo):

http://download.csdn.net/detail/flcop/6993665

http://blog.csdn.net/flcop/article/details/20240703

Delphi Android integrates Google ZXing (call jar file)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.