I followed the tutorial here to install the phonegap plugin in my Android project.
The version of Cordova (PhoneGap) is 2.3.0, and I download the plugin from this github link;
Here is my code where I try to call the barcode scanner:
window.plugins.barcodeScanner.scan(success,
function(error) {
alert("scanning failed: " + error)
}
);
When I press the button to call the method, I get the following error:
scanning failed : Class not found.
What am I doing wrong?
Add the line:
<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
to you res/xml/config.xml file.
Add the line to you res/xml/config.xml file:
<feature name="BarcodeScanner"><param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" /></feature>
Related
I have a problem with the barcode scanner plugin (I'm not a genius and I don't know well how to programm a web-app.).
I use phonegap and cordova and I've tried to do a web-app that scan a barcode after a click on a link.
I've installed the plugin, before with this command line:
cordova plugin add cordova-plugin-barcodescanner
and I write this js code:
function scan(){
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
in html:
Scan
But when I click on the link, It doesn't happen anything.
If I put an alert after: function scan(){, it show
if I put an alert after: cordova.plugins.barcodeScanner.scan(, doesn't do anything.
So, I tried to uninstall the plugin and install it with this command line:
cordova plugin add com.phonegap.plugins.barcodescanner
With the same js and html code, but it doesn't work yet.
So, I uninstall the plugin and I try to install it with:
cordova plugin add https://github.com/wildabeast/BarcodeScanner.git
But anything yet.
I search a lot and I try a lot of solutions!
I use cordova 5.0.0 and I try the plugin on android 4.4 and IOS.
I also installed the plugin camera.
So, please, help me! Where is the error?
I followed all the solutions that I've find on the web and on stackoverflow.
The code always crashes after:
cordova.plugins.barcodeScanner.scan(
Can anyone help me, please?
Thank you so much.
First of all can you check your code in firefox with firebug, see if it is giving some error which can let you to do so or you can try other library which is intelXDK
document.addEventListener("intel.xdk.device.barcode.scan",function(evt){});
You have to add the feature to the config.xml in case of Android as below:
<feature name="BarcodeScanner">
<param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>
I have tried to implement this Datetimepicker ( https://github.com/VitaliiBlagodir/cordova-plugin-datepicker ) but still not working on my Android Device ( Android 4.0.4).
I added the plugin to my Project and used : cordova plugin add https://github.com/VitaliiBlagodir/cordova-plugin-datepicker.
Put a Trigger to my js file and tried to test a alert("test"). I get the test alert on browser and on Device, but no alert from Datetimepicker?
I also rm Android from Platform and build it again, everything is there, but still not working. ( To build the app, i am using PhoneGap Build)
I have no idea what I am missing? .... any help would be nice :-).
Example:
in Html
<input type="text" onclick="calendar()" />
in JS
<script>
function calendar(){
alert("test") // is working
var options = {
date: new Date(),
mode: 'date'
};
datePicker.show(options, function(date){
alert("date result " + date); // not working
});
}
</script>
You don't have to add the script in your path.
Make sur you have register the plugin to your config.xml like so :
<feature name="DatePicker">
<param name="ios-package" value="DatePicker"/>
</feature>
<feature name="DatePickerPlugin">
<param name="android-package" value="com.okaybmd.cordova.plugin.datepicker.DatePickerPlugin"/>
</feature>
(more info # http://phonegap-plugins.com/plugins/okaybmd/cordova-plugin-datepicker )
The plugin won't work in your browser.
You have to test it through your device or an emulator.
Did you include your script in your HTML ?
<script src="your/path/DatePicker.js"></script>
The datepicker returns a promise, so you need to handle that on your code.
<script>
function calendar(){
alert("test") // is working
var options = {
date: new Date(),
mode: 'date'
};
datePicker.show(options).then(function(date){
alert("date result " + date);
});
}
</script>
Also, I have always used this with Angular, so not completely sure on how you inject the service for your usage.
Reference: http://ngcordova.com/docs/plugins/datePicker/
I used it for developing and Ionic app. The idea was to simply add the plugin (datepicker) and include ngCordova and ngCordovaMocks js files in your resources and the HTML.
ngCordovaMocks is for web development.
The injection was done while building apk or ipa at the main module
app.module('asas',['ngCordova'],function($cordovaDatePicker){
}).run()
I installed the FacebookConnect plugin into my cordova project with the code:
cordova -d plugin add /Users/your/path/here/phonegap-facebook-plugin --variable APP_ID="123456789" --variable APP_NAME="myApplication"
Then linked the Facebook API (3.8.0) in /platforms/android/project.properties with:
android.library.reference.2=../../facebook-android-sdk-3.8.0/facebook
Then copied the example 'Simple' into the /www folder, added my app id and changed phonegap.js to cordova.js.
When I compile and run the application on my android phone I receive the following errors:
Cordova Facebook Connect plugin fail on init
Cordova Facebook Connect plugin fail on auth.status
and on login:
Cordova Facebook Connect plugin fail on login!Class not found
LogCat gives the following error:
exec() call to unknown plugin: org.apache.cordova.facebook.Connect
I've scoured the internet but cannot find a solution to this problem.
I did notice that my /platforms/android/res/xml/config.xml file lists the plugin as:
<feature name="FacebookConnectPlugin">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
When the Documentation says that it should be:
<feature name="org.apache.cordova.facebook.Connect">
<param name="ios-package" value="FacebookConnectPlugin" />
</feature>
But I can't change this as it's automatically generated during the compiling process.
Did you remember to copy (from the download) www/cdv-plugin-fb-connect.js, www/facebook-js-sdk.js into your apps www folder?
I got the same error, managed to fix by updating my root config.xml (which isn't generated) to include:
<feature name="org.apache.cordova.facebook.Connect">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
(Note android-package as looks like you are using android.)
This is under the manual install section of the readme, but also seems to be necessary after following the automatic install process.
Now you can execute cordova build android from the root, bob's your uncle.
As of 6/13/14 this is what works for me, so I laid out my steps on PasteBin.
http://pastebin.com/WvQvqx6U
Basically just reverted back to 0.4.0 of Facebook Connect.
It's working perfectly for me, and I didn't have any issues setting it up.
I am trying to create a Cordova Plugin using IBM Worklight. I followed the instructions mentioned in the IBM Worklight Getting Started page, but while checking trying it on a device I get the following:
02-13 17:58:15.182: D/PluginManager(21057): exec() call to unknown
plugin: SamPlugin
I added the plugin in Config.xml as follows:
<plugin name="SamPlugin" value="com.samapp.plugins.samplugin.SamPlugin"/>
and then, i called the plugin from my JavaScript file as follows:
cordova.exec(success,failure,"SamPlugin","printMsg",[name]);
There are no errors while building the application.
Do I need to mention the plugin anywhere else?
Looks to me like the way you have declared the plug-in in config.xml is incorrect...
This:
<plugin name="SamPlugin" value="com.samapp.plugins.samplugin.SamPlugin"/>
Should be:
<feature name="SamPlugin">
<param name="android-package" value="com.testapp.SamPlugin" />
</feature>
The above is the way Cordova plug-ins are declared in Cordova 3.x; Worklight 6.1 uses Cordova 3.1.
The above assumes you are using Worklight 6.1, because you mentioned that you've followed a Getting Started training module, which is now based on Worklight 6.1... If you are using a different Worklight version, you must mention the version number.
For example - an application that implements a Cordova plug-in that shares a link to a question via the native email app installed on the device (this doesn't really matter, it's just a "scenario"):
HTML:
<button onclick="openExternalApp()">Share Question</button>
JavaScript:
function openExternalApp() {
var QUESTION_LINK = $(".question_link").attr("href");
cordova.exec(onSuccess, onFailure, "OpenExternalAppPlugin", "openApp", [QUESTION_LINK]);
}
function onSuccess() {
WL.Logger.debug("*** Plug-in executed successfully.");
}
function onFailure() {
WL.Logger.debug("*** Plug-in failed to execute.");
}
android\native\res\xml\config.xml:
<feature name="OpenExternalAppPlugin">
<param name="android-package" value="com.testapp.OpenExternalAppPlugin" />
</feature>
android\native\src\com\YOUR_APP\OpenExternalAppPlugin.java:
The Java file containing the Java code of the Cordova plug-in...
i am trying to develop an android application using cordova. for my application, i require the barcode scanner plugin (https://github.com/wildabeast/BarcodeScanner/)
i am unable to add the plugin using CLI, so i downloaded and copied the files, added the plugin via the following:
<feature name="BarcodeScanner">
<param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>
i then added references to the barcodescanner.js and the cordova files in my application. then in my index, i added the following lines of code to read barcode:
var scanner = cordova.plugins.barcodeScanner;
scanner.scan(
function(result){
alert("Scanned Code: " + result.text
+ ". Format: " + result.format
+ ". Cancelled: " + result.cancelled);
},
function(error){
alert("Scan failed: " + error);
}
);
}
but i get the following error:
Uncaught TypeError: Cannot read property 'barcodeScanner' of undefined
due to that, i think the cordova.plugins is undefined. what may be the issue for this? am i missing anything?
I have made a simple project for you and have added barcode scanner plugin through CLI from github.
You can download my Project from here.
After Downloading, import it and check few things with your project like
Plugins package name in src folder and its code
config.xml
AndroidManifest.xml
Hope this will help you out.