如何将ZXING导入android studio?

AM0*_*447 11 java import android zxing android-studio

我使用android studio我想在我的应用程序中导入'ZXING',我发现很多文章并找到了以下网站

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

我下载了ZIP并解压缩,并找到了一些教程但是它似乎没有太详细的细节,我需要导入什么?实现QRCode扫描

我仍然不知道该怎么做


4/14我尝试了Lennon URL提供的"zxing-android-minimal"并导入'gradle-wrapper.jar'

但是当我写了新的IntentIntegrator(this).initiateScan(); 仍然出现"无法解析符号'IntentIntegrator"消息

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

我有一个正确的'.jar选择添加为库但是当发生错误时,他似乎没有被添加


4/10

终于不再出现"无法解析符号'IntentIntegrator"这是代码,我有什么不对?

我删除了新的IntentIntegrator(this).initiateScan(); '应用程序正常运行

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

我的'build.greadle'

    repositories {
    jcenter()
    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}
Run Code Online (Sandbox Code Playgroud)

Len*_*ick 9

当我使用zxing库开发我的应用程序时,我遇到了很多麻烦.所以看看这个zxing minimal:https://github.com/Promptus/zxing-android-minimal/tree/master

它对我来说很完美,并且更容易实现.

编辑:

在项目中打开此文件:

/gradle/wrapper/gradle-wrapper.properties

编辑distributionUrl行并设置它:

distributionUrl = http://services.gradle.org/distributions/gradle-1.8-all.zip重建您的项目.

更新:您现在可能想要使用gradle-2.1-all.zip.

新编辑:

首先,您必须删除您的libs文件.然后你必须删除

mavenCentral()
    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
Run Code Online (Sandbox Code Playgroud)

从你的角度build.gradle来看MyApplication,因为gradle是针对整个项目的,所以你最好在每个模块中使用它.

之后,打开build.gradle模块app并添加以下代码:

repositories {
    mavenCentral()

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'

    // Zxing libraries
    compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
    compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
    compile 'com.google.zxing:core:3.0.1'

}
Run Code Online (Sandbox Code Playgroud)

最后,您需要google.zxing.integration.android从项目中删除,否则,编译时会出现错误.

更新:

要解决后退按钮问题,您可以执行以下代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {

        String _code = data.getStringExtra("SCAN_RESULT");

        // do whatever you want

    }

}
Run Code Online (Sandbox Code Playgroud)


kre*_*sak 8

您应该在build.gradle文件中定义zxing依赖项:

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.zxing:core:3.2.0'
}
Run Code Online (Sandbox Code Playgroud)

这是Core条形码编码/解码库,您可以使用它来构建自定义条形码扫描器/生成器应用程序.

如果您只需支持扫描条形码的简单案例,您可以使用ZXing Android Embedded项目嵌入ZXing Android Barcode Scanner应用程序.

这是ZXing Android Barcode Scanner应用程序的一个端口,作为Android库项目,用于嵌入其他Android应用程序.

如果您决定使用ZXing Android Embedded项目,那么就像在build.gradle文件中定义依赖项一样简单:

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'
}
Run Code Online (Sandbox Code Playgroud)

使用默认选项启动intent:

new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
Run Code Online (Sandbox Code Playgroud)

得到你的结果:

@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;
    }
}
Run Code Online (Sandbox Code Playgroud)


Chr*_*her 5

在你的root-build.gradle中:

repositories {
   mavenCentral()

   maven {
      url "http://dl.bintray.com/journeyapps/maven"
   }
}
Run Code Online (Sandbox Code Playgroud)

在你的app-build.gradle中:

dependencies {
    // Supports Android 4.0.3 and later (API level 15)
    compile 'com.journeyapps:zxing-android-embedded:2.3.0@aar'

    // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
    // If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
    compile 'com.journeyapps:zxing-android-legacy:2.3.0@aar'

    // Convenience library to launch the scanning Activities.
    // It automatically picks the best scanning library from the above two, depending on the
    // Android version and what is available.
    compile 'com.journeyapps:zxing-android-integration:2.3.0@aar'

    // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
    // This mostly affects encoding, but you should test if you plan to support these versions.
    // Older versions e.g. 2.2 may also work if you need support for older Android versions.
    compile 'com.google.zxing:core:3.2.0'
}
Run Code Online (Sandbox Code Playgroud)

更多信息可以在这里找到:https://github.com/journeyapps/zxing-android-embedded