Skip to content

Commit 7739249

Browse files
Merge pull request #2923 from CatimaLoyalty/fix/2921
Only pass encoding hint in automatic if UTF-8
2 parents 8252f52 + 2308deb commit 7739249

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.ref.WeakReference;
2323
import java.nio.charset.Charset;
2424
import java.util.Map;
25+
import java.util.Objects;
2526

2627
import protect.card_locker.async.CompatCallable;
2728

@@ -190,7 +191,16 @@ private Bitmap generate() {
190191
} else {
191192
String guessedEncoding = StringUtils.guessEncoding(cardId.getBytes(), new ArrayMap<>());
192193
Log.d(TAG, "Guessed encoding: " + guessedEncoding);
193-
encodeHints.put(EncodeHintType.CHARACTER_SET, Charset.forName(guessedEncoding));
194+
195+
// We don't want to pass the gussed encoding as an encoding hint unless it is UTF-8 as
196+
// zxing is likely to add the mentioned encoding hint as ECI inside the barcode.
197+
//
198+
// Due to many barcode scanners in the wild being badly coded they may trip over ECI
199+
// info existing and fail to scan, such as in https://github.com/CatimaLoyalty/Android/issues/2921
200+
if (Objects.equals(guessedEncoding, "UTF8")) {
201+
Log.d(TAG, "Guessed encoding is UTF8, so passing as encoding hint");
202+
encodeHints.put(EncodeHintType.CHARACTER_SET, Charset.forName(guessedEncoding));
203+
}
194204
}
195205

196206
BitMatrix bitMatrix;

0 commit comments

Comments
 (0)