window.plugins and cordova.plugins always undefined

17 posts, 0 answers
  1. Kareem
    Kareem avatar
    2 posts
    Member since:
    Oct 2013

    Posted 08 Oct 2013 Link to this post

    I'm trying to get the barcode scanner plugin to work in my project. The sample works perfectly fine.

    No matter what I try window.plugins is undefined. I saw a thread saying as of 3.0 that I should be accessing plugins via cordova.plugins. That's also undefined. 
    I can't see the difference between what I have and the sample. 

    Here's what I did to try to get the plugin setup.
    1. Install the plugin
    2. From an onclick event handler trying accessing cordova.plugins or window.plugins. 

    Am I missing something? All testing is done on an actual device.

    Any help would be great.
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 09 Oct 2013 Link to this post

    Hi Kareem,

    The problem with your sample is that you have forgotten to copy the www folder as part of the BarcodeScanner plugin i.e. the javascript API of the plugin is missing. On a side note, window.plugins is now deprecated in Cordova 3.0 and should not be used i.e window.plugins would return undefined, but window.plugins.barcodeScanner would return an object.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  3. marco
    marco avatar
    33 posts
    Member since:
    Sep 2007

    Posted 11 Oct 2013 Link to this post

    Hi Steve,

    It's 36 hrs that I'm fighting with this issue, and I haven't found any solution, I have tried mainly everything also to replicate exactly how the barcodescanner has been implemented in the GitHub project, but it doesn't work at all. If I clone the github project it works, otherwise it doesn't.

    I have created a project in Icenium online,
    I have added the barcodeScanner plugin using Icenium interface.
    I have copied&pasted the html code in a new blank html page as you can find in the github project
    I have copied and pasted the code of the main.js file as you can find on the github project.
    I have built it.
    Installed on the device (Galaxy Nexus Android 4.3)
    --->> window.plugins has no property barcodeScanner error

    Nothing to do, where is the problem?!?
    Please help me!!

    Regards
    Marco
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Oct 2013 Link to this post

    Hello Marco,

    I have used your TestBarcodeScanner app and it works correctly when deployed on couple of Android devices including Nexus 4. If that is not the app you refer to, please let us know its name and we would take a look. In general such errors could mean that either the plugin is not registered correctly or you're trying to invoke javascript API before Cordova has loaded. Neither of this is the case in your test app.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  5. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 30 Dec 2013 Link to this post

    Hi,

    I have same problem with both window/cordova .plugins property being always undefined using Android 2.3.4. Even the GitHub scanner sample does it. Is this a known problem with my OS version? I would like to know before trying to update it.

    UPDATE: just tried it with iPhone 4S (7.0.4) and everything works. Is there a way to make it work with the Android version mentioned above?

    TIA
  6. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 31 Dec 2013 Link to this post

    Hello Martin,

    Unfortunately, we do not have an Android 2.3.4 mobile device for testing at the moment. We've built the Barcode Scanner and deployed it on 2.3.3 and 2.3.6 devices and we haven't been able to reproduce your issue. The sample app runs as expected (with a distinctive delay between tapping the Scan button and launching the scanner).

    The window/cordova.plugins undefined error is typically related to the deviceready event not firing properly. Would you try placing the <script> includes for both cordova and the main.js file in the <head> and let us know if that solves the problem?

    In addition, you might try explicitly setting the target SDK version for your app. Edit your AndroidManifest.xml file to have the following lines: 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="10" />

    You can learn how to edit your AndroidManifest.xml file from here

    Regards,
    Iva Koevska
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  7. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 31 Dec 2013 Link to this post

    Hi Iva,

    same erroneous behaviors with the two recommendations you've suggested. Ill try tonight with the iPhone and let you know if it still works on it (but I assume it will)
  8. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 31 Dec 2013 Link to this post

    Hi Martin,

    Can you attach a copy of your project or let us know what the project name is, so we can take a look at the code (as we were not able to reproduce it with the Barcode Scanner sample). You can learn how to export your project here.

    Regards,
    Iva Koevska
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  9. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 31 Dec 2013 Link to this post

    this sample is called sample-barcode-scanner. How can I attach it? the extension filter blocks my .zip file to be attached

    TIA
  10. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 03 Jan 2014 Link to this post

    Hi Martin,

    The project you pointed us to is basically the BarCodeScanner sample we provide and as my colleague mentioned, the project works when deployed on 2.3.3 (Samsung Galaxy S2) and 2.3.6 (Nexus S) devices.

    If your Android device has an Android update to 4.x already available, we recommend upgrading to it and trying again. Also, do you mind sharing what the device model is?

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  11. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 03 Jan 2014 Link to this post

    Hi, my device is a Samsung Galaxy Ace GT-S5830D and if im not mistaken, I cant upgrade the device to 4.x
  12. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 03 Jan 2014 Link to this post

    Hi Martin,

    We do not have that device locally and indeed there does not seem to be an official update for it. There are unofficial Android ports for it, but this would void warranty (if any left). Anyway, bottom line is this problem must be device specific as the BarCodeScanner sample works on all 2.x devices we have. In general if you need an Android device to test your hybrid apps, we would recommend using one with clean Android (Nexus device).

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  13. Kevin
    Kevin avatar
    1 posts
    Member since:
    Dec 2014

    Posted 24 Dec 2014 in reply to Kareem Link to this post

    Hi Kareem,

    I'm stuck at the same problem since a day. In my case, I'm getting cordova.exec as 'undefined' in wp8. Also cordova.plugins isn't accessible and that too returns me undefined. Did anyone come with a solution to the same ?
    Any help would be appreciated.
  14. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 24 Dec 2014 Link to this post

    Hi Kevin,

    In most cases, this error means that you have code that depends on the cordova.exec() function and is being invoked before the device is ready. Please, check your logic and remove any custom code that could be instantiating this function, after the deviceready event. Here is a stackoverflow thread on the same matter as well.

    I hope this helps.

    Regards,
    Kaloyan
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  15. sai
    sai avatar
    2 posts
    Member since:
    May 2015

    Posted 12 May 2015 in reply to Kaloyan Link to this post

    In PhoneGap,I created a sample barcode scanning app. 

    but If I click the scan code button,window.plugin is undefined msg will come. 

    Please tell me what is mistake i did it.

     Here paste my login of calling barcode scanning,

    var scanCode = function() {
    alert (cordova.plugins.barcodeScanner);
    cordova.plugins.barcodeScanner.scan(
    function(result) {
    alert("Scanned Code: " + result.text 
                    + ". Format: " + result.format
                    + ". Cancelled: " + result.cancelled);
        }, function(error) {
            alert("Scan failed: " + error);
        });
    }

  16. sai
    sai avatar
    2 posts
    Member since:
    May 2015

    Posted 12 May 2015 in reply to sai Link to this post

    Anyone Give me sample code of barcode scanner in phonegap.

     If I click the scan code button nothing happening in device.

     var scanCode = function() {
        cordova.plugins.barcodeScanner.scan(
            function(result) {
            alert("Scanned Code: " + result.text 
                    + ". Format: " + result.format
                    + ". Cancelled: " + result.cancelled);
        }, function(error) {
            alert("Scan failed: " + error);
        });
    }
    Pls do the needful.

    Regards

    Sai.

     

     

  17. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 14 May 2015 Link to this post

    Hi Sai,

    It is important to say that the barcodeScanner object can be used only after the deviceReady event has fired. In other words, you can check if the pasted code would work executed on deviceready.

    I would recommend you to check the BarcodeScanner sample app in our documentation. Trying it in AppBuilder, you will notice the scripts\main.js file in which the JS code for the BarcodeScanner functionality resides.

    Further, you can also check the BarcodeScanner sample from the Telerik Verified Plugin Marketplace. It explains how the plugin works in even greater details.

    I hope this helps.

    Regards,
    Kaloyan
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top