Hi, I need to develop a barcode scanner for android I followed the in indications found here:
http://www.raymondcamden.com/2014/3/5/Barcode-Scanner-sample-and-new-repo-for-Cordova-examples;
I have a button on my application, when it is clicked the scanner starts, it finds the code and suddenly close the application without throwing any error, so I am stuck. Any help appreciated
Some code would help…
Can you point to a github repo?
Are you using Ng-cordova?
What device are you testing on?
Hello, I created a repo: https://github.com/arpho/scannerTest
Sorry I am not able to say whether I am using ng-cordova, I followed this: https://github.com/wildabeast/BarcodeScanner.
The device is a samsung galaxy star with android 4.1.2
thanks for your time.
Hmm that sample is pretty old.
You should look at using ng-cordova with an ionic project.
This will help you get things going an to stop you app from crashing.
Sorry same behavior, you can find the code on https://github.com/arpho/Scanner
Try the Barcode scanner found at the following repo: https://github.com/Eccenux/BarcodeScanner
It is a fork of the wildabeast plugin and this one I was able to successfully use in an Ionic + Cordova 3.5 project for both iOS and Android.
For iOS you will need to modify the XCode project settings a little:
- Add CDVBarcodeScanner.mm to Build Phases -> Compile Sources
- Add QuarzCore, CoreVideo, ImageIO frameworks to Build Phases -> Link Binary With Libraries
- Make sure libiconv.dylib (left pane: Project -> Frameworks) has a checked checkbox for Target Membership (right pane)
Sorry I do not know how to install the plugin if I use:
cordova plugins add https://thub.com/Eccenux/BarcodeScanner.git like the old post it installs something, but I am not sure if it is the right way maybe using plugman is better, but I do not understand how to use it:
with : plugman install android https://github.com/Eccenux/BarcodeScanner.git
I get an error `Object # has no method ‘help’
`
It should just install using “cordova plugin add”
But to give some valuable hard learned advice… never expect a repository outside of your control to be available as long as you need it. That said, here’s what I typically do
- fork the github repo so you can keep it alive as long as you need it and potentially hack away at it. (and if you made some awesome additions/changes you could help us all out and send a pull request to the original repository)
- clone the repo to your development machine or add as a git submodule to your app project
At the existing project root of your cordova app just use cordova-cli:
cordova plugin add /path/to/the/plugin/dir
cordova build
If this all goes well you should be able to see the plugin added to your project. Check the contents of the AndroidManifest.xml if you have Android enabled as a platform, you can do the same to config.xml for ios found here:
project_root/platforms/ios/<app_name>/config.xml
Using the BarcodeScanner plugin is really simple:
cordova.plugins.barcodeScanner.scan(
function (result) {
// scanner was successfully spawned and has exited
if (result.cancelled === 0) {
// barcode found
// type of barcode is stored in result.format
// barcode data is stored in result.text
} else {
// barcode scanner was cancelled by user
}
},
function (error) {
// handle error here
}
);
thanks a lot for your advice, but even with this plugin, I have the same problem.
If it’s of any help I was having the same issue on a n5 with android 5+. I solved it using this hack:
function scan() {
var detachBarcodeScannerBackHandler = $ionicPlatform.registerBackButtonAction(function () {
detachBarcodeScannerBackHandler();
}, 1000);
$cordovaBarcodeScanner.scan().then(function(barcodeData) {
if (!barcodeData.cancelled) {
detachBarcodeScannerBackHandler();
}
}, function(error) { console.log(error); });
}
So if the action is cancelled all back actions are overridden by mine which simply detaches itself so subsequent back click run as normal. If on the other hand the action was a success I call the detach handler directly.
The problem was the version of android, with the last version the plug-in Worked perfectly