Re: [PhoneGap] BarCode Scanner plugin.

775 views
Skip to first unread message

Simon MacDonald

unread,
Jan 22, 2013, 9:51:31 PM1/22/13
to phonegap

Reproduce the bug while running "adb logcat".

On Jan 22, 2013 7:01 PM, <al...@isite.co.nz> wrote:
Hi,

I have app that is using PhoneGap and barcode plugin (from phonegap git hub)  scanner, testing on Android 4 and Android 2, on Samsung mini and Samsung SIII. I have flowed your tutorial how to install the plugin and set-up the project. All works fine until I get to the point to scan the barcode, plugin is triggered and I can scan the code but then the app is reverted back to index.html every single time ( no pop-up alert from example code ) and basically kills the app, as the index checks some stuff from remote server. The error on the end is that connection to remote server can not be established. I know that my communication with remote server works fine,  I am guessing that app is reverted to index and at the same time none of the JS code (DOM) is initialised. I am using JQuery and JQuery Mobile, all latest versions.

I have no idea how to fix this. Any help is appreciated. I can post my Manifest and config xml files if that helps.

Thanks, Alex


--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 

al...@isite.co.nz

unread,
Jan 23, 2013, 6:16:27 PM1/23/13
to phon...@googlegroups.com
Hi Simon,

Thank you for your reply. I have found the problem. It was a setting on my developer option on the phone it self. Working now, but does not return pop-up every time.
It scans the barcode fine, but then camera is still active and I can scan more codes, if I press "return" button on the phone it self, then it is back to page and pop-ups the latest scan.

I am new in this and using Eclipse, how I can run  "adb logcat".? I am using linux.

Thanks
Alex

Simon MacDonald

unread,
Jan 23, 2013, 6:21:28 PM1/23/13
to phonegap

al...@isite.co.nz

unread,
Jan 23, 2013, 6:42:46 PM1/23/13
to phon...@googlegroups.com
Hi Simon,

Great, thank you. I should have found it my self. It is obvious place to look for answers.

al...@isite.co.nz

unread,
Feb 1, 2013, 3:12:56 AM2/1/13
to phon...@googlegroups.com
Hi,

Thank you for your answers. Now I have different problem.
The plugin is working, but when the barcod is scanned, displays the code fine, then when scanners is closed and returned to phonegap app, screen flickers (like closing and opening page that has invoked the plugin). Then if I scan again different bar-code (or same)  - it won't close and return to phonegap, it just sits on the screen active and does not return to phonegap. It happens every time on any subsequent scan.

I am not sure what might be the problem, nothing in log. I have to press 'return' button  on phone it self to close it, and then it pop-ups the barcode scan result and returns to phonegap app..

Any help is very much appreciated.

Thanks, Alex

Simon MacDonald

unread,
Feb 1, 2013, 9:18:53 AM2/1/13
to phonegap
That's really weird. I've never been able to reproduce this issue. I
can keep scanning barcodes without any problems. What reproduction
scenario can you provide, code, etc?

Simon Mac Donald
http://hi.im/simonmacdonald


> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>
> To compile in the cloud, check out build.phonegap.com
> ---
> You received this message because you are subscribed to the Google Groups
> "phonegap" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to phonegap+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

al...@isite.co.nz

unread,
Feb 1, 2013, 1:17:55 PM2/1/13
to phon...@googlegroups.com
HI,

I can send the whole www (ziped) folder. I am suspecting that it is due to bad jQuery code, because when I am using example code (only one page) it works fine. Especially I am not sure how to get pages ready properly into DOM. I am using jQuery mobile for GUI.

Should I send you the code? It is not big, few MB.

Thanks

al...@isite.co.nz

unread,
Feb 1, 2013, 10:14:13 PM2/1/13
to phon...@googlegroups.com
Hi,

The barcode scanner works fine if I invoke only the plugin.
For example:

$('#scanme-page').live('pageinit', function(event) {
    $("#scan-code-button").live('tap', function() {
        scan();     // call scan function
    });     
     
});

And this is scan function:

function scan() {
    window.plugins.barcodeScanner.scan(function(result) {
            $("#barcode-info").val(result.text);
        }, function(error) {
            alert("Scanning failed: " + error + " Please enter code manualy");
        });
}

It just updates the text box in html with the value of the code. That works perfectly, every time, I can scan as many times I like.  But if I add for example code to store the code to local db (or any other code, get geolocation, redirect to other page):

function scan() {
    window.plugins.barcodeScanner.scan(function(result) {
            var db = getDB();
            db.transaction(function(tx) {tx.executeSql('insert into installlog (prod_code,latitude,longitude,status) values ("'+tebarcode+'","'+latitude+'","'+longitude+'","1")');}, function(e) {console.log("ERROR: " + e.message);}, function(tx, res) {});
            $.mobile.changePage("scanform.html", { transition: "slide"});   
        }, function(error) {
            alert("Scanning failed: " + error + " Please enter code manualy");
            $.mobile.changePage("manual.html", { transition: "fade"});
        });
}

It scans correctly only first time then starts that strange behaviour. Even if I go all way back to index page and start from beginning.

Any idea why is this happening? How should I invoke the scanner correctly do avoid this happening all the time?

Simon MacDonald

unread,
Feb 3, 2013, 12:05:48 PM2/3/13
to phonegap
Sorry, I'm by no means a jQuery Mobile expert. What happens when you don't transition to another page but you still store stuff in the DB?




--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com

Veronica Bendersky

unread,
Jul 19, 2013, 2:23:40 PM7/19/13
to phon...@googlegroups.com
Hi Alex,

Could you tell me what setting you had to change to fix this problem? I'm having the same problem now.

Thank you.

Regards,
Veronica

bogos...@gmail.com

unread,
Jul 20, 2013, 8:29:12 PM7/20/13
to phon...@googlegroups.com
Hi Veronica,

Unfortunately I can not remember what I have done.
But, I just finished the project for retail book shop, scans the barcode of any book and calls the remote API to check the price and with option to buy now.
I have followed this https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner to implemented the barcode as library into my project. Please note that phonegap/cordova changed
the implementation of the plugins. If building with phonegap build, use new version.
Here is the code how I have done it, works without any problems, it may help, it is a basic book example,I didn't need to modify it:

// page from where scanner is invoked
$('#home-page').bind('pagecreate', function(event) {
    $("#scan").on("vclick",function(e) { // button with id 'scan'
        scan(); //call scan function
    })
});


function scan() {
    // new way of plugin implementation - does not work localy for me
    var scanner = cordova.require("cordova/plugin/BarcodeScanner");
    //old way - use which ever works in your case
   //var scanner = window.plugins.barcodeScanner;

    localStorage.setItem("scannedbarcode",null);

            scanner.scan(function(args) {
                console.log("Scanner result: \n" +
                    "text: " + args.text + "\n" +
                    "format: " + args.format + "\n" +
                    "cancelled: " + args.cancelled + "\n");
                if(args.cancelled){
                        localStorage.removeItem("scannedbarcode");
                       // if you wish to redirect to any page
                       // $.mobile.changePage("#home-page", "none", true,false);
                        return;
                }
               localStorage.setItem("scannedbarcode", args.text);
                 getProduct(args.text,1); // call remote API
                 console.log(args);
        }, function(error) {
            navigator.notification.alert("Scanning failed, please try again.",null,'Error','OK');
        });

}

I think that I had something wrong in developer settings on Samsung Galaxy S, didn't enabled USB debugging or something, got Samsung S4 now, works fine, tested this code on quiet old Android phones in the customer office, the only problem was on old phones that it took some time for camera to focus on barcode, other than that was OK.

Anyway, my settings on old S phone:
USB debugging ON and Allow mock location and enable installation from Unknown source
Same options enabled on S4.

As I said before, I am new to this PhoneGap business, coming from PHP background, and still learning JQuery and JQMobile.

Let me know if this works for you.

Alex
Reply all
Reply to author
Forward
0 new messages