Skip to content

Commit 24d0294

Browse files
authored
Merge pull request #665 from journeyapps/fixes
v4.3.0
2 parents 4026027 + 6ccf3a9 commit 24d0294

File tree

23 files changed

+798
-364
lines changed

23 files changed

+798
-364
lines changed

.github/workflows/build.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build Android
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/setup-java@v2
12+
with:
13+
distribution: 'temurin'
14+
java-version: '11'
15+
- name: Build and Lint with Gradle
16+
run: ./gradlew build
17+
- name: Archive lint results
18+
uses: actions/upload-artifact@v2
19+
with:
20+
name: lint-results
21+
path: "**/build/reports/lint-results*"

.travis.yml

-36
This file was deleted.

CHANGES.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
### 4.3.0 (2021-10-25)
2+
3+
* Minimum SDK version 19, but requires additional config (see readme) for < 24 compatibility.
4+
* Add ScanOptions and ScanContract for use with `registerForActivityResult()`.
5+
* Deprecates IntentIntegrator.
6+
* Use minimal AndroidX libraries.
7+
8+
### 4.2.0 (2021-03-15)
9+
10+
* Fix MediaPlayer warnings (#587).
11+
* Prevent CameraConfigurationUtils clash (#609).
12+
* Add licenses to POM (#556).
13+
* Bug: Crashes on SDK versions older than 21 (#645).
14+
115
### 4.1.0 (2020-01-07)
216

317
* Ability to hide the laser in ViewfinderView (#503).

README.md

+67-58
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,61 @@ repositories {
2727
}
2828
2929
dependencies {
30-
implementation 'com.journeyapps:zxing-android-embedded:4.2.0'
31-
implementation 'androidx.appcompat:appcompat:1.0.2'
30+
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
3231
}
33-
34-
android {
35-
buildToolsVersion '28.0.3' // Older versions may give compile errors
36-
}
37-
3832
```
3933

4034
## Older SDK versions
4135

42-
For Android SDK versions < 24, you can downgrade `zxing:core` to 3.3.0 or earlier for Android 14+ support:
36+
By default, only SDK 24+ is supported, even though the library specifies 19 as the minimum version.
37+
No guarantees are made on support for SDK versions below 24 - you'll have to test to make sure it's compatible.
38+
39+
SDK versions 19 - 23 should also work, but one of the changes changes below are required,
40+
and this is not routinely tested.
41+
42+
### Option 1. Downgrade zxing:core to 3.3.0
4343

4444
```groovy
4545
repositories {
4646
mavenCentral()
4747
}
4848
4949
dependencies {
50-
implementation('com.journeyapps:zxing-android-embedded:4.2.0') { transitive = false }
51-
implementation 'androidx.appcompat:appcompat:1.0.2'
50+
implementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
5251
implementation 'com.google.zxing:core:3.3.0'
5352
}
53+
```
5454

55+
### Option 2: Desugaring (Advanced)
56+
57+
This option does not require changing library versions, but may complicate the build process.
58+
59+
See [Java 8+ API desugaring support](https://developer.android.com/studio/write/java8-support#library-desugaring).
60+
61+
```groovy
5562
android {
56-
buildToolsVersion '28.0.3'
57-
}
63+
defaultConfig {
64+
// Important: multidex must be enabled
65+
// https://developer.android.com/studio/build/multidex#mdex-gradle
66+
multiDexEnabled true
67+
minSdkVersion 19
68+
}
5869
59-
```
60-
You'll also need this in your Android manifest:
70+
compileOptions {
71+
// Flag to enable support for the new language APIs
72+
coreLibraryDesugaringEnabled true
73+
// Sets Java compatibility to Java 8
74+
sourceCompatibility JavaVersion.VERSION_1_8
75+
targetCompatibility JavaVersion.VERSION_1_8
76+
}
77+
}
6178
62-
```xml
63-
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
79+
dependencies {
80+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
81+
implementation "androidx.multidex:multidex:2.0.1"
82+
}
6483
```
6584

66-
No guarantees are made on support for older SDK versions - you'll have to test to make sure it's compatible.
67-
6885
## Hardware Acceleration
6986

7087
Hardware acceleration is required since TextureView is used.
@@ -75,48 +92,42 @@ Make sure it is enabled in your manifest file:
7592
<application android:hardwareAccelerated="true" ... >
7693
```
7794

78-
## Usage with IntentIntegrator
95+
## Usage with ScanContract
7996

80-
Launch the intent with the default options:
81-
```java
82-
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
83-
84-
85-
// Get the results:
86-
@Override
87-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
88-
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
89-
if(result != null) {
90-
if(result.getContents() == null) {
91-
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
92-
} else {
93-
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
94-
}
95-
} else {
96-
super.onActivityResult(requestCode, resultCode, data);
97-
}
98-
}
99-
```
97+
Note: `startActivityForResult` is deprecated, so this example uses `registerForActivityResult` instead.
98+
See for details: https://developer.android.com/training/basics/intents/result
10099

101-
Use from a Fragment:
102-
```java
103-
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
100+
`startActivityForResult` can still be used via `IntentIntegrator`, but that is not recommended anymore.
104101

105-
// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.
102+
```java
103+
// Register the launcher and result handler
104+
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
105+
result -> {
106+
if(result.getContents() == null) {
107+
Toast.makeText(MyActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
108+
} else {
109+
Toast.makeText(MyActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
110+
}
111+
});
112+
113+
// Launch
114+
public void onButtonClick(View view) {
115+
barcodeLauncher.launch(new ScanOptions());
116+
}
106117
```
107118

108119
Customize options:
109120
```java
110-
IntentIntegrator integrator = new IntentIntegrator(this);
111-
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
112-
integrator.setPrompt("Scan a barcode");
113-
integrator.setCameraId(0); // Use a specific camera of the device
114-
integrator.setBeepEnabled(false);
115-
integrator.setBarcodeImageEnabled(true);
116-
integrator.initiateScan();
121+
ScanOptions options = new ScanOptions();
122+
options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
123+
options.setPrompt("Scan a barcode");
124+
options.setCameraId(0); // Use a specific camera of the device
125+
options.setBeepEnabled(false);
126+
options.setBarcodeImageEnabled(true);
127+
barcodeLauncher.launch(options);
117128
```
118129

119-
See [IntentIntegrator][5] for more options.
130+
See [BarcodeOptions][5] for more options.
120131

121132
### Generate Barcode example
122133

@@ -152,9 +163,9 @@ Sample:
152163
```
153164

154165
```java
155-
IntentIntegrator integrator = new IntentIntegrator(this);
156-
integrator.setOrientationLocked(false);
157-
integrator.initiateScan();
166+
ScanOptions options = new ScanOptions();
167+
options.setOrientationLocked(false);
168+
barcodeLauncher.launch(options);
158169
```
159170

160171
### Customization and advanced options
@@ -198,7 +209,7 @@ You can then use your local version by specifying in your `build.gradle` file:
198209

199210
Licensed under the [Apache License 2.0][7]
200211

201-
Copyright (C) 2012-2018 ZXing authors, Journey Mobile
212+
Copyright (C) 2012-201 ZXing authors, Journey Mobile
202213

203214
Licensed under the Apache License, Version 2.0 (the "License");
204215
you may not use this file except in compliance with the License.
@@ -216,7 +227,5 @@ Licensed under the [Apache License 2.0][7]
216227

217228
[1]: http://journeyapps.com
218229
[2]: https://github.com/zxing/zxing/
219-
[3]: https://github.com/zxing/zxing/wiki/Scanning-Via-Intent
220-
[4]: https://github.com/journeyapps/zxing-android-embedded/blob/2.x/README.md
221-
[5]: zxing-android-embedded/src/com/google/zxing/integration/android/IntentIntegrator.java
230+
[5]: zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanOptions.java
222231
[7]: http://www.apache.org/licenses/LICENSE-2.0

build.gradle

+4-16
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ buildscript {
22
repositories {
33
google()
44
mavenCentral()
5-
jcenter {
6-
content {
7-
// https://youtrack.jetbrains.com/issue/IDEA-261387
8-
includeModule("org.jetbrains.trove4j", "trove4j")
9-
}
10-
}
115
}
126

137
dependencies {
14-
classpath 'com.android.tools.build:gradle:3.5.3'
8+
classpath 'com.android.tools.build:gradle:7.0.3'
159
}
1610
}
1711

@@ -20,17 +14,11 @@ subprojects {
2014
google()
2115
mavenLocal()
2216
mavenCentral()
23-
jcenter {
24-
content {
25-
// https://youtrack.jetbrains.com/issue/IDEA-261387
26-
includeModule("org.jetbrains.trove4j", "trove4j")
27-
}
28-
}
2917
}
3018

31-
version = '4.2.0'
19+
version = '4.3.0'
3220
group = 'com.journeyapps'
3321

34-
ext.androidTargetSdk = 28
35-
ext.zxingCore = 'com.google.zxing:core:3.4.0'
22+
ext.androidTargetSdk = 30
23+
ext.zxingCore = 'com.google.zxing:core:3.4.1'
3624
}

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
android.enableJetifier=true
1+
android.enableJetifier=false
22
android.useAndroidX=true
33
org.gradle.jvmargs=-Xmx1536M

gradle/wrapper/gradle-wrapper.jar

5.25 KB
Binary file not shown.
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Sat Sep 07 15:17:02 SAST 2019
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip

0 commit comments

Comments
 (0)