Re: How to scan barcode from webview

1,889 views
Skip to first unread message

Lachezar Dobrev

unread,
Jul 27, 2012, 4:19:45 AM7/27/12
to zxing
Right...
Some time ago I helped another developer on the list with a similar situation.
The guy's name is Guy Ronen.
To my greatest shame I could not find the code I sent to him.
Dig a bit through the discussion group's archive.

Mainly you will need to subclass WebViewClient, and handle manually
the requests to open the ZXing Bar-Code scanner.

I will try to be more helpful by looking for the actual code...

2012/7/27 Gabriel <gabriel....@googlemail.com>:
> I'm trying to develop webview app which need to scan barcode. I use
> IntentIntegrator and following code in JavaScriptInterface:
> protected void onActivityResult(int requestCode, int resultCode, Intent
> data)
> {
> switch(requestCode)
> {
> case IntentIntegrator.REQUEST_CODE:
> {
> if (resultCode != Activity.RESULT_CANCELED)
> {
> IntentResult scanResult =
> IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
> if (scanResult != null)
> {
> barcode = scanResult.getContents();
> showToast(barcode);
> }
> }
> break;
> }
> }
> }
>
>
>
> On my website I have following code:
>
> <script type="text/javascript">
> var count = 0;
> function scan() {
> Android.scanBarcode();
> }
>
> var count = 0;
> var handle;
>
> function checkBarcode() {
>
> if (count < 0) {
> window.clearInterval(handle);
> return;
> }
> debug.innerHTML = "check... " + count;
> var s = Android.getBarcode();
> if (s != "") {
> debug.innerHTML = s;
> Android.clearBarcode();
> }
> }
>
> function ScanBarcode() {
> count = 10;
> scan();
> handle = window.setInterval("checkBarcode()", 500);
> }
> </script>
>
>
> but after returning from camera view I see in debug only "check... 10" and
> nothing more. How can I get the scanned characters?
>
>
> Regards, Gabriel
>
> --
>
>
>

Gabriel

unread,
Jul 27, 2012, 5:02:17 AM7/27/12
to zx...@googlegroups.com
I've found that I need to place onActivityResult in MainActivity (it is the single one), not in JavaScriptInterface.
I'm getting correct display from showToast(...), but there is one problem remaining: I need to get the value from JavaScriptInterface into html and also process it on my webserver. Until now remains display empty.


Am Freitag, 27. Juli 2012 10:19:45 UTC+2 schrieb Lachezar:
 Right...
  Some time ago I helped another developer on the list with a similar situation.
  The guy's name is Guy Ronen.
  To my greatest shame I could not find the code I sent to him.
  Dig a bit through the discussion group's archive.

  Mainly you will need to subclass WebViewClient, and handle manually
the requests to open the ZXing Bar-Code scanner.

  I will try to be more helpful by looking for the actual code...

2012/7/27 Gabriel
Message has been deleted

Gabriel

unread,
Jul 27, 2012, 7:43:52 AM7/27/12
to zx...@googlegroups.com
I solved it - simply reload http page from MainActivity with QueryString set to barcode.

Sujay Patil

unread,
Oct 23, 2013, 5:37:53 PM10/23/13
to zx...@googlegroups.com
Hi Gabriel ,
can you please post your complete code. I have integrated Zxing in my Android app but now want it to be called inside a web view. Like start the CaptureActivity inside my WebView. Just want to know if you had similar situation and did you resolved? Now when i try to open start 
CaptureActivity inside my web view the ZXing Scanner page covers the whole screen.

Thank you...

Danish Mohammad Ahshan

unread,
Apr 6, 2014, 12:16:15 AM4/6/14
to zx...@googlegroups.com
Hi ,
Could you please send me complete code for 1d bar code reader in Javascript; I have to populate barcode in a input file in web page on chrome in andriod mobile.

Please suggest me; how to go ahead.

Thankd, Danish

ANUJ GROVER

unread,
Sep 2, 2017, 4:01:23 PM9/2/17
to zxing

Please provide us the complete code if you have solved i need this solution too i am stuck on same code

ANUJ GROVER

unread,
Sep 2, 2017, 4:02:08 PM9/2/17
to zxing, mailto...@gmail.com
You found any solution please get back to me i am also stuck in this situation
Reply all
Reply to author
Forward
0 new messages