Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.jlmcdonnell:zxing-android-embedded:v3.4.0'
}
dependencies {
implementation("com.github.jlmcdonnell:zxing-android-embedded:v3.4.0")
}
<dependency>
<groupId>com.github.jlmcdonnell</groupId>
<artifactId>zxing-android-embedded</artifactId>
<version>v3.4.0</version>
</dependency>
libraryDependencies += "com.github.jlmcdonnell" % "zxing-android-embedded" % "v3.4.0"
:dependencies [[com.github.jlmcdonnell/zxing-android-embedded "v3.4.0"]]
Barcode scanning library for Android, using ZXing for decoding.
The project is loosely based on the ZXing Android Barcode Scanner application, but is not affiliated with the official ZXing project.
Features:
A sample application is available in Releases.
From version 3 this is a single library, supporting Gingerbread and later versions of Android (API level 9+). If you need support for earlier Android versions, use version 2.
Add the following to your build.gradle file:
repositories {
jcenter()
}
dependencies {
compile 'com.journeyapps:zxing-android-embedded:3.4.0'
compile 'com.android.support:appcompat-v7:23.1.0' // Version 23+ is required
}
android {
buildToolsVersion '23.0.2' // Older versions may give compile errors
}
Launch the intent with the default options:
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
// Get the results:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
Use from a Fragment:
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.
Customize options:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
See IntentIntegrator for more options.
To change the orientation, specify the orientation in your AndroidManifest.xml
and let the ManifestMerger
to update the Activity's definition.
Sample:
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setOrientationLocked(false);
integrator.initiateScan();
See EMBEDDING.
For more advanced options, look at the Sample Application, and browse the source code of the library.
The camera permission is required for barcode scanning to function. It is automatically included as part of the library. On Android 6 it is requested at runtime when the barcode scanner is first opened.
When using BarcodeView directly (instead of via IntentIntegrator / CaptureActivity), you have to
request the permission manually before calling BarcodeView#resume()
, otherwise the camera will
fail to open.
./gradlew assemble
To deploy the artifacts the your local Maven repository:
./gradlew publishToMavenLocal
You can then use your local version by specifying in your build.gradle
file:
repositories {
mavenLocal()
}
JourneyApps - Creating business solutions with mobile apps. Fast.