Understanding how to use Intent Integrator with two scan buttons

709 views
Skip to first unread message

cj

unread,
Feb 24, 2012, 3:17:11 AM2/24/12
to zxing
Hi there, I've been using the android SDK for a whole 2 hrs so please
bear with me if I dont quite understand what I'm doing.

So I've created a little app, with one activity, that contains some
text boxes and two buttons, each where I wanted to using zxing to do
that scanning. So i implemented first button, textbox, used the
intentintegrator, worked great. I now wanted to add a second button,
but here is where I dont get it, since I cannot tell the difference
between which button was pressed, both will just call the one event
onActivityResult. Is this just a caveat, and I'll probably need to
import all of the source of zxing, since my needs will not work with
intents?

here is the simple little app so far.

package com.example.helloandroid;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void doWOScan(View view) {
IntentIntegrator.initiateScan(this);
}

public void doTaskScan(View view) {
IntentIntegrator.initiateScan(this);
}

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

IntentResult scanResult =
IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
Toast.makeText(this, scanResult.getContents() ,
Toast.LENGTH_SHORT).show();
}
// else continue with any other code you need in the method

}

}

Thanks,
Cameron

Sean Owen

unread,
Feb 25, 2012, 1:27:54 PM2/25/12
to zx...@googlegroups.com
For this you need to use different request codes on the call to start activity. You would have to modify the integrator code because it always uses just one particular one. Its not hard. You could provide a patch to tthe integrator to expose the request code too if you are willing.
Reply all
Reply to author
Forward
0 new messages