15

I'm trying to add the Phonegap Barcode scanner plugin to my Phonegap app. I'm primarily developing for windows phone 8 but I also want to target the ios and android platforms. I managed to add the plugin correctly, but when I start the scan, my windows phone doesn't recognize any barcodes. It just shows the video screen with a focus button and a green square.

Here's my code for the scan:

    function Scan() {
      window.plugins.barcodeScanner.scan(function (result) {
        barcode = result;
        alert(barcode.text);
      }, function (error) {
        alert("Scanning failed: " + error);
      });
  };

this function is called on deviceready event.

Am I doing something wrong? Or did I miss something in the plugin? I read that android and need to set permission to execute this plugin. Do I need permission to enable it to scan in windows phone too?

UPDATE :

It seems I can scan QR code but not the regular one(SCC code). Someone have a clue on this?

Amit Singh
  • 2,698
  • 21
  • 49
Janick Isabelle
  • 434
  • 7
  • 18
  • What kind of barcode is "the regular one"? UPC-A? – Enrico Mar 19 '13 at 16:55
  • Thanks for the reply. I need to scan SCC code. – Janick Isabelle Mar 19 '13 at 21:10
  • According to the readme, SCC-14 is not one of the supported types. https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner – Gambit Mar 19 '13 at 23:11
  • I don't think you need to set permissions on Windows Phone, I didn't have to when I implemented a barcode scanner in my application. Also, out of curiosity, which plugins are using? When I last looked, the Windows Phone ZXing port only included the code to read barcodes, it didn't include code to launch the camera and detect a barcode, I had to look elsewhere for that. – Ciaran Gallagher Mar 20 '13 at 00:02
  • @Gambit IIUC, GS1-128 is a type of Code 128 barcode. According to the ZXing FAQs, [1D scanning is disabled by default on iOS](http://code.google.com/p/zxing/wiki/FrequentlyAskedQuestions#Why_don%27t_1D_codes_work_on_iOS_devices?), could that also be the case in WP8? – Enrico Mar 20 '13 at 11:31
  • I was able build and deploy my solution on ipod with the phonegap build. And the Ipod was able to scan the barcode – Janick Isabelle Mar 20 '13 at 12:31
  • 1
    @CiaranG i use the plugin available in the github of phonegap-plugin [link]https://github.com/phonegap/phonegap-plugins/tree/master/WindowsPhone/BarcodeScanner/deploy – Janick Isabelle Mar 20 '13 at 14:49

1 Answers1

3

Try using the ZXing Barcode Scanner for Windows Phone. It works quite well.

http://silverlightzxing.codeplex.com

You can call the class you create using PhoneGap. Then let the native plugin for ZXing do all the heavy work, and return back the code scanned to you in Javascript using the success function.

SashaZd
  • 3,315
  • 1
  • 26
  • 48
  • mmm i think Phonegap will not take it very well if i try to build it for ios or android – Janick Isabelle Apr 04 '13 at 14:03
  • whyever not ? I have an app in which I'm doing precisely that. Phonegap doesn't aim to limit your work. Most of their plugins are created by developers themselves. In this case, you're using Phonegap to call a native plugin or the ZXing plugin. Doesn't really matter. If it works, great ! – SashaZd Apr 04 '13 at 14:05
  • Ah no, I actually build it on my own, using the Phonegap API Plugin for XCode (in iOS) or Eclipse (for Android), and so on. I found that's much more reliable, and almost as easy and painless. Why don't you build it yourself ? It easy, and plus then you can use as many external libraries and frameworks that you need without a care. – SashaZd Apr 04 '13 at 15:11
  • My team and i found it more easy to write only one project and updating it than build 3 project (maybe 4 cause blackberry will maybe come later). But thanks for your point. Maybe we will just use the adobe phonegap build for ios and android and develevop our own version of windows phone – Janick Isabelle Apr 04 '13 at 17:23
  • I know it's a bit late but i mark you as the answer cause we really need to build it on your own for every os and i used the plugin you mention. – Janick Isabelle May 28 '13 at 19:55