1

I'm new to android developement and I'm trying to use zxing to my google glass application, and it scans successfully. However when I'm tapping the glass for the result, nothing happens. But, when I'm swiping it down the activity is closing and execute the code in RESULT_CANCEL option in onActivityResult. That's why I'm confuse.

Am I getting the result back to my activity or not? I reasearched a lot and I tried different solutions but nothing works.

This is my code:

Main Activity

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    scan();
    setContentView(R.layout.activity_main);
}

private void scan(){
    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(intent, 0);
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
       if (resultCode == RESULT_OK) {

          String contents = intent.getStringExtra("SCAN_RESULT");
          String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

          Toast.makeText(getApplicationContext(), contents + format, Toast.LENGTH_LONG).show();

          // Handle successful scan

       } else if (resultCode == RESULT_CANCELED) {
          // Handle cancel
          Log.i("App","Scan unsuccessful");
       }
    }

Manifest:

<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
    <action android:name="com.google.zxing.client.android.SCAN"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity> 

I'am missing something? Any help would be much appreeiated.

rapidoodle
  • 340
  • 1
  • 3
  • 23

1 Answers1

0

If the scan is successful, you shouldn't need to swipe down to go back to your activity: zxing activity should finish itself and return the result back to your app. When you swipe down, zxing will return RESULT_CANCELED.

So, your problem is why zxing doesn't finish its activity and return the result. Please see this question, it answered by one of zxing developers. He suggested you should use IntentIntegrator. Also, this answer shows how to do it.

Community
  • 1
  • 1
pt2121
  • 11,720
  • 8
  • 52
  • 69
  • I already tried the IntentIntegrator but it's asking to download the barcodeapp but since I'm using glass, it's not possible to download the ap from there. – rapidoodle Jan 27 '15 at 00:55