Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import ZXING to android studio?

I use android studio I want to import 'ZXING' in my application, I find many articles and found the following site

https://github.com/zxing/zxing/

I downloaded the ZIP and unzip, and find some tutorials But it does not seem to be too detailed about the details, what I need to import? To achieve QRCode scan

I still have no idea how to do it


4/14 I tried Lennon URL provided "zxing-android-minimal" And import the 'gradle-wrapper.jar'

But when I wrote new IntentIntegrator (this) .initiateScan (); Still appear "Can not resolve symbol 'IntentIntegrator" message

https://www.dropbox.com/s/2srga9iq75iqe4m/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96%202015-04-10%2001.33.56.png?dl=0

I do have a right '.jar select Add As Library But when an error occurs, he does not seem to be added


4/10

Finally no longer appear "Can not resolve symbol 'IntentIntegrator" this is the code,What do I wrong?

I removed the new IntentIntegrator (this) .initiateScan (); 'applications normal operation

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new IntentIntegrator(this).initiateScan();
}

my 'build.greadle'

    repositories {
    jcenter()
    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}
like image 596
AM031447 Avatar asked Apr 08 '15 11:04

AM031447


1 Answers

You should define your zxing dependency in build.gradle file:

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.zxing:core:3.2.0'
}

This is the Core barcode encoding/decoding library which you can use to build your custom barcode scanner/generator app.

If you need to support just a simple case of scanning the barcode you can embed ZXing Android Barcode Scanner application using ZXing Android Embedded project.

This is a port of the ZXing Android Barcode Scanner application as an Android library project, for embedding in other Android applications.

If you decide to use the ZXing Android Embedded project it's as easy as defining your dependencies in build.gradle file:

repositories {
    mavenCentral()

    maven {
        url "http://dl.bintray.com/journeyapps/maven"
    }
}

dependencies {
    implementation 'com.journeyapps:zxing-android-embedded:2.3.0@aar'
    implementation 'com.journeyapps:zxing-android-legacy:2.3.0@aar'
    implementation 'com.journeyapps:zxing-android-integration:2.3.0@aar'
    implementation 'com.google.zxing:core:3.2.0'
}

Launch the intent with the default options:

new IntentIntegrator(this).initiateScan(); // `this` is the current Activity

And get your result:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode) {
    case IntentIntegrator.REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            // Parsing bar code reader result
            IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        }
        break;
    }
}
like image 53
krebernisak Avatar answered Sep 22 '22 17:09

krebernisak