I've an activity in my app which Either picks an image from gallery to scan for a barcode and then displays the result in a TextView
and picked image in an ImageView
OR starts the camera to scan one and displays the result in the respective TextView
.
I'm using Google Mobile Vision API (indirectly through a Library just to skip the boiler plate code) and the scanning works impressively fast.
I've tried my best to find a way before asking this question through searching the sample project of the library and Google Mobile Vision API and the internet but failed to find one.
How can I pass the actual scanned barcode to an ImageView
(or an Activity)? (seems impossible directly)
My code is basically this (just with some intents etc)
@Override
public void onRetrieved(final Barcode barcode) {
Log.d(TAG, "Barcode read: " + barcode.displayValue);
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setTitle("code retrieved")
.setMessage(barcode.displayValue);
builder.show();
}
});
}
// for multiple callback
@Override
public void onRetrievedMultiple(final Barcode closetToClick, final List<BarcodeGraphic> barcodeGraphics) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String message = "Code selected : " + closetToClick.displayValue + "\n\nother " +
"codes in frame include : \n";
for (int index = 0; index < barcodeGraphics.size(); index++) {
Barcode barcode = barcodeGraphics.get(index).getBarcode();
message += (index + 1) + ". " + barcode.displayValue + "\n";
}
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setTitle("code retrieved")
.setMessage(message);
builder.show();
}
});
}
@Override
public void onBitmapScanned(SparseArray<Barcode> sparseArray) {
for (int i = 0; i < sparseArray.size(); i++) {
Barcode barcode = sparseArray.valueAt(i);
Log.e("value", barcode.displayValue);
}
}
@Override
public void onRetrievedFailed(String reason) {
// in case of failure
}
}
Above code works great but is there a way possible to use that SparseArray
for obtaining the actual scanned barcode?