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>
Related
I have an Ionic project and I installed this plugin to scan qrcodes:
cordova plugin add https://github.com/wildabeast/BarcodeScanner.git
But when I run the app on a samsung s5 device with Android 6.0 I get a camera error:
"Sorry, the Android camera encountered a problem. You may need to restart the device"
Any ideas of what causes this issue?
I have tested with:
ionic run android -l -c
ionic run android
This is my code executed when I press a button:
$scope.scanBarcode = function() {
$ionicPlatform.ready(function() {
$cordovaBarcodeScanner.scan().then(function(imageData) {
console.log("Barcode text -> " + imageData.text);
console.log("Barcode Format -> " + imageData.format);
console.log("Cancelled -> " + imageData.cancelled); // prints: cancelled
}, function(error) {
console.log("An error happened -> " + error);
});
});
};
For this issue you can try either of below solutions:
1) It is permission issue with android 6. So to fix the issue configure platform to android 5.0.
OR if you are using MI note 4 you can try below additional steps:
There is another permission required in MIUI secruity system and after enabling it, camera started working.
Following are the steps you can follow to update the setting:
1) Go to Security.
2) Click on “Permissions” and again select “Permissions”
3) Now from the list, click on “Camera”.
4) It will list all the apps installed. Look for your app and enable the permission.
Reff: http://sforsuresh.in/cordova-sorry-android-camera-encountered-problem/
This is what solved my problema, in the config.xml file in the "android" platform section I put:
<platform name="android">
<preference name="android-targetSdkVersion" value="22"/>
</platform>
I'm developing a crossplatform application in HTML5/CSS/JS using Phonegap 5.1.1. I'm struggling to find a solution to integrate the official phonegap-plugin-barcodescanner, following the instructions which the official page on GitHub refers to. In detail, after building through Phonegap Build, I can't get rid of the Help page which appears as soon as I start the app on Android (see the ). This way I cannot test if everything's working fine.
Furthermore, I've found out there are loads of ways to initialize the plugin and I'd like to know whether I'm doing anything wrong. Here's the code in my page:
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.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);
});
Finally, I've modified my config.xml as to include:
<gap:plugin name="BarcodeScanner"/>
Any suggestions?
Thanks in advance.
please add bellow permissions
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
I found the solution myself. In case anyone is looking for a ready-to-use way to start, here's the way to go.
If you're using Phonegap Build online service, you need not add any plugin via
phonegap plugin add <plugin_name> (or cordova plugin add). It'll be sufficient to simply mimic the behavior of the official Phonegap BarcodeScanner Demo, particularly as regards the files:
<appname>/config.xml (referencing the plugin com.phonegap.plugins.barcodescanner);
<appname>/index.html (which includes the line <script src="barcodescanner.js" />);
<appname>/js/index.js (which contains the scan and encode methods, as well as their initialization).
As soon as the app is built, Phonegap Build will inject the official plugin by itself within the package.
Edit: What's with the down vote? My question was well-researched and I don't believe that I deserved it.
I know that there are several questions addressing cordova.plugins being undefined, but I've been unable to find a resolution with all my research.
I'm targeting only the Android platform.
I'm trying to use the phonegap barcodescanner plugin and am consistently running into errors trying to use it. I always get the error: Cannot read property 'barcodeScanner' of undefined
Setup information:
Phonegap version: 3.5.0-0.20.4
Not using phonegap build
Cordova version: 3.5.0-0.2.6
Installed plugin using all of the following methods (independently, of course, for testing)
Instructions here https://github.com/wildabeast/BarcodeScanner/tree/master/src/android
cordova plugins add https://github.com/wildabeast/BarcodeScanner.git
phonegap plugin add https://github.com/wildabeast/BarcodeScanner.git
Also tried substituting http://github.com/phonegap-build/BarcodeScanner.git for the wildabeast version
From what I can tell, the plugin installs correctly.
I've used 3 different methods to test what I'm doing: Browser (primarily Chrome), Ripple Chrome Extension, and the Phonegap Developer App. I get the error in the browser and Ripple, but nothing happens at all in the Phonegap Developer App.
The code is very simple.
The page it's being called from:
<div ng-controller="StorageMainCtrl">
<p ng-click="doScan()">Scan!</p>
</div>
The controller code handling the scan:
$scope.doScan = function() {
cordova.plugins.barcodeScanner.scan(
function (result) {
var s = "Result: " + result.text + "<br/>" +
"Format: " + result.format + "<br/>" +
"Cancelled: " + result.cancelled;
alert(s);
},
function (error) {
alert("Scanning failed: " + error);
}
);
};
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.
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>