how to simulate a succesful barcode scan (on an emulator in eclipse)

1,398 views
Skip to first unread message

Novice

unread,
Oct 26, 2011, 9:33:24 PM10/26/11
to zxing
Hello guys!

Disclaimer: I am new to Android programming, so please answer like you
would to your grandma :)

How can I simulate a successful barcode scan (for testing purposes) on
an emulator in Eclipse?

I have succeeded in setting up Zxing on the emulator (with the
IntentIntegrator.java and IntentResult.java files) and added some code
to capture the barcode number in a textView. This works well on my
phone.

I want to add a few lines of code that simulate a successful scan so I
can add some more functionality without having to test on my phone.

This is the Result handler I have in my main java file:

protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
switch(requestCode) {
case IntentIntegrator.REQUEST_CODE: {
if (resultCode != RESULT_CANCELED) {

IntentResult scanResult =
IntentIntegrator.parseActivityResult(requestCode, resultCode, data);

if (scanResult != null) {

String upc = scanResult.getContents();


//WHAT CODE CAN I ADD AND WHERE SO I CAN SEND THE PROGRAM DIRECTLY TO
THIS POINT

TextView tv = new TextView(this);
tv.setText(upc);
setContentView(tv);

}
}
break;
}
}
}

Sean Owen

unread,
Oct 27, 2011, 1:28:52 AM10/27/11
to zx...@googlegroups.com
I would just hack your app to pretend it has an IntentResult at this point -- that is, create your own mock object. You can test how it works that way. It's not ideal but yeah hard to otherwise test a scan on the emulator; I'd really suggest just testing on your phone. I have actually never ever used the Android emulator to test; just adb install it on my phone every time.

MCON Dev

unread,
Oct 27, 2011, 12:44:59 PM10/27/11
to zx...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages