I\'m writing this in mere desperation :) I\'ve been assigned to make a standalone barcode scanner (as a proof of concept) to an Android 1.6 phone.
For this i\'ve dis
I just wrote a method, which decodes generated bar-codes, Bitmap
to String
.
It does exactly what is being requested, just without the CaptureActivity
...
Therefore, one can skip the android-integration
library in the build.gradle
:
dependencies {
// https://mvnrepository.com/artifact/com.google.zxing
compile('com.google.zxing:core:3.3.0')
compile('com.google.zxing:android-core:3.3.0')
}
The method as following (which actually decodes generated bar-codes, within a jUnit test):
import android.graphics.Bitmap;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.Result;
protected String decode(Bitmap bitmap) {
MultiFormatReader reader = new MultiFormatReader();
String barcode = null;
int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
BinaryBitmap binary = new BinaryBitmap(new HybridBinarizer(source));
try {
Result result = reader.decode(binary);
// BarcodeFormat format = result.getBarcodeFormat();
// ResultPoint[] points = result.getResultPoints();
// byte[] bytes = result.getRawBytes();
barcode = result.getText();
} catch (NotFoundException e) {
e.printStackTrace();
}
return barcode;
}