I am trying to create a Glass app which scans a barcode and uses the information in the barcode to open a specific document.
After having trouble building ZXing from source for Glass, I turned to an already created port called BarcodeEye: https://github.com/BarcodeEye/BarcodeEye
However, it seems that BarcodeEye does not have built in support for using it as an intent. I added the intent-action to the manifest. This allows me to call BarcodeEye from my app, but I am having trouble with where to call setResult in order to get a result with the text of my QR from barcodeEye.
Can anybody with experience with ZXing help me to understand why there is no result returned and where to put the setResult code to properly return a result.
Here is the code I am using to call BarcodeEye in my app:
Intent intent = new Intent("com.github.barcodeeye.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
startActivityForResult(intent, 0);
And here is my result class:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
Log.v("zxing",contents);
} else
if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
Any help with how to get the proper activity result would be greatly appreciated.
EDIT:
I was able to get it barely working by adding the intent filter and putting the data return in the CaptureActivity.java
class. This works for me since the QR's I care about are text only, but I don't think my current method would work in some cases since it doesn't run it through the filter to check what type of QR it is.
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chut.glass.xively"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_xi"
android:label="@string/app_name" >
<uses-library
android:name="com.google.android.glass"
android:required="true" />
<activity
android:name="com.chut.glass.xively.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger" />
</activity>
<service android:name="com.jessefarebro.mqtt.MqttService" android:exported="false" />
</application>
</manifest>
Here is where I ended up putting the data return in CaputreActivity:
// Put up our own UI for how to handle the decoded contents.
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 data = new Intent();
data.putExtra("SCAN_RESULT", rawResult.toString());
if (getParent() == null) {
setResult(Activity.RESULT_OK, data);
Log.v(TAG,"parent null");
} else {
Log.v(TAG,"parent: " + getParent());
getParent().setResult(Activity.RESULT_OK, data);
}
Log.v(TAG,"about to finish");
finish();
Log.v(TAG,"post finish");
//startActivity(ResultsActivity.newIntent(this, processor.getCardResults(), imageUri));
}
I have a fork of BarcodeEye in which I have restored/added the Intent functionality of ZXing: https://github.com/paulpv/BarcodeEye/tree/intent I have opened a Pull Request back upstream to see if BarcodeEye will take it. I am also discussing w/ zxing the possibility of writing an official GDK Glassware version of their Barcode Scanner (CaptureActivity)