Integrating the ZXing library directly into my Android application

后端 未结 17 1419
[愿得一人]
[愿得一人] 2020-11-22 04:35

I\'m writing this in mere desperation :) I\'ve been assigned to make a standalone barcode scanner (as a proof of concept) to an Android 1.6 phone.

For this i\'ve dis

相关标签:
17条回答
  • 2020-11-22 05:18

    Much Easier approach.

    Just include dependency in your app level gradle file

    compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar'
    compile 'com.google.zxing:core:3.2.0'  
    

    Define one button in your xml file and and write below code in Java file in OnCreate()and inside the OnClick listener of button

    new IntentIntegrator(this).initiateScan();
    

    And write below code after OnCreate() of the Java file

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if(result != null) {
            if(result.getContents() == null) {
                Log.d("MainActivity", "Cancelled scan");
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
            } else {
                Log.d("MainActivity", "Scanned");
                String st_scanned_result = result.getContents();
                Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
    
            }
        }
    
    }
    
    0 讨论(0)
  • 2020-11-22 05:19

    If you just need the core.jar from zxing, you can skip that process and get the pre-built JARs from the GettingStarted wiki page

    Latest ZXing (2.2) doesn't have core.jar under core folder but you can obtain the core.jar from the zxing Maven repository here

    0 讨论(0)
  • 2020-11-22 05:20

    Having issues building with ANT? Keep reading

    If ant -f core/build.xml says something like:

    Unable to locate tools.jar. Expected to find it in
    C:\Program Files\Java\jre6\lib\tools.jar
    

    then set your JAVA_HOME environment variable to the proper java folder. I found tools.jar in my (for Windows):

    C:\Program Files\Java\jdk1.6.0_21\lib
    

    so I set my JAVA_HOME to:

    C:\Progra~1\Java\jdk1.6.0_25
    

    the reason for the shorter syntax I found at some site which says:

    "It is strongly advised that you choose an installation directory that does not include spaces in the path name (e.g., do NOT install in C:\Program Files). If Java is installed in such a directory, it is critical to set the JAVA_HOME environment variable to a path that does not include spaces (e.g., C:\Progra~1); failure to do this will result in exceptions thrown by some programs that depend on the value of JAVA_HOME."

    I then relaunched cmd (important because DOS shell only reads env vars upon launching, so changing an env var will require you to use a new shell to get the updated value)

    and finally the ant -f core/build.xml worked.

    0 讨论(0)
  • 2020-11-22 05:20

    Have you seen the wiki pages on the zxing website? It seems you might find GettingStarted, DeveloperNotes and ScanningViaIntent helpful.

    0 讨论(0)
  • 2020-11-22 05:21

    The

    compile 'com.google.zxing:core:2.3.0'
    

    unfortunately didn't work for me.

    This is what worked for me:

    dependencies {
       compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar'
       compile 'com.google.zxing:core:3.2.0'
    }
    

    Please find the link here: https://github.com/journeyapps/zxing-android-embedded

    0 讨论(0)
  • 2020-11-22 05:25

    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.
    9. Reference link: Using ZXing to create an android barcode scanning app
    0 讨论(0)
提交回复
热议问题