This is a migrated thread and some comments may be shown as answers.
window.plugins and cordova.plugins always undefined
16 Answers 641 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kareem
Top achievements
Rank 1
Kareem asked on 08 Oct 2013, 09:12 PM
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.

16 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 09 Oct 2013, 12:19 PM
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.
0
marco
Top achievements
Rank 2
answered on 11 Oct 2013, 09:37 AM
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
0
Steve
Telerik team
answered on 14 Oct 2013, 12:29 PM
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.
0
Martin Roussel
Top achievements
Rank 1
answered on 30 Dec 2013, 07:47 PM
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
0
Iva Koevska
Telerik team
answered on 31 Dec 2013, 09:07 AM
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.
0
Martin Roussel
Top achievements
Rank 1
answered on 31 Dec 2013, 12:20 PM
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)
0
Iva Koevska
Telerik team
answered on 31 Dec 2013, 12:57 PM
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.
0
Martin Roussel
Top achievements
Rank 1
answered on 31 Dec 2013, 01:23 PM
this sample is called sample-barcode-scanner. How can I attach it? the extension filter blocks my .zip file to be attached

TIA
0
Steve
Telerik team
answered on 03 Jan 2014, 01:05 PM
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.
0
Martin Roussel
Top achievements
Rank 1
answered on 03 Jan 2014, 01:30 PM
Hi, my device is a Samsung Galaxy Ace GT-S5830D and if im not mistaken, I cant upgrade the device to 4.x
0
Steve
Telerik team
answered on 03 Jan 2014, 02:05 PM
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.
0
Kevin
Top achievements
Rank 1
answered on 24 Dec 2014, 06:49 AM
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.
0
Kaloyan
Telerik team
answered on 24 Dec 2014, 12:39 PM
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.

 
0
sai
Top achievements
Rank 1
answered on 12 May 2015, 05:42 AM

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);
    });
}

0
sai
Top achievements
Rank 1
answered on 12 May 2015, 01:37 PM

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.

 

 

0
Kaloyan
Telerik team
answered on 14 May 2015, 11:49 AM
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.

 
Tags
Apache Cordova
Asked by
Kareem
Top achievements
Rank 1
Answers by
Steve
Telerik team
marco
Top achievements
Rank 2
Martin Roussel
Top achievements
Rank 1
Iva Koevska
Telerik team
Kevin
Top achievements
Rank 1
Kaloyan
Telerik team
sai
Top achievements
Rank 1
Share this question
or