Open mcongrove opened 10 years ago
In theory this shouldn't be too difficult to implement. I'm assuming you would want back the data scanned, not simply handled by the current workflow (which is primarily to do searches online). You would still need to include the source, mark it as a library, add a manifest entry, and then some lines of code to start the startActivityForResult
.
I'll give it a shot and if successful add the instructions to the README.
That's exactly what I was thinking; I'd love to be able to drop this into an app and simply listen for data to come back, which I could then handle as necessary. Would really simplify development for a lot of Glass apps, I think.
Thanks for taking a look into it.
Any progress on this? I wanted to setup an intent to use your scanner but noticed there was no intent to launch the app. I have added this but am having trouble getting the data back from the resultsActivity, was this functionality removed? Since it isn't functioning as it does in the standard ZXing on android? Can you provide any insight on how to get a result from the scan?
I achieved this by taking this fork https://github.com/pub-burrito/BarcodeEye
modifying the CaptureActivity handleDecodeInternally(Result rawResult, Bitmap barcode)
to
private void handleDecodeInternally(Result rawResult, Bitmap barcode) {
Uri imageUri = null;
String imageName = IMAGE_PREFIX + System.currentTimeMillis() + ".png";
Log.v(TAG, "Saving image as: " + imageName);
try {
imageUri = mImageManager.saveImage(imageName, barcode);
} catch (IOException e) {
Log.e(TAG, "Failed to save image!", e);
}
ResultProcessor<?> processor = ResultProcessorFactory
.makeResultProcessor(this, rawResult, imageUri);
Intent returnIntent = new Intent();
returnIntent.putExtra("result",processor.getCardResults().get(0).getFooter());
setResult(RESULT_OK,returnIntent);
finish();
}
To start up the intend I did:
Intent objIntent = CaptureActivity.newIntent(this, true);
objIntent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(objIntent, BARCODE_REQUEST);
Note: You will also need to modify your AndroidManifest.
This code is bad, especially this line returnIntent.putExtra("result",processor.getCardResults().get(0).getFooter());
its just to give you an idea of what you need to do to scan a barcode using an intent
.
If your firing this intent from a menu you need to make sure your not finishing the menu when you call this as there will be nothing to pass the result back to and the onActivityResult
will never be called http://stackoverflow.com/questions/21337093/onactivityresult-never-called-for-speech-intent-on-google-glass
Would be nice to be able to just drop this into my GDK project to add barcode scanning. Any plans to make this into a package?