Adding PhoneGap barcode-scanner to Wordpress / Apppresser - android

I built an Android/IOS app based on Wordpress using Apppresser. Based on this doc http://docs.apppresser.com/article/163-adding-phonegap-plugins I try to add this phonegap plugin https://github.com/phonegap/phonegap-plugin-barcodescanner into my app.
I added
<gap:plugin name="phonegap-plugin-barcodescanner" source="npm">
<param name="CAMERA_USAGE_DESCRIPTION" value="To scan barcodes." />
</gap:plugin>
and
<preference name="android-build-tool" value="gradle" />
to my config.xml and built the app. The apk finally includes the barcodescanner.js so all looks good. Following the above Apppresser doc I created a demo.js file with
var wp = document.getElementById('myApp').contentWindow;
wp.document.getElementById("scan-barcode").addEventListener("click", function(){
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);
}
);
});
and added it to my Wordpress installation (I did that prior to building the app using the online Apppresser building tool and prior to building the apk-file). Finally I created a Wordpress page and added
<input type="button" value="click" name="click" id="click"/>
I suppose a click should open the camera on my device but nothing happens...
Anyone out there where I may have gotten lost on the way?
Any help would be highly appreciated.
Thanks.

Related

cordova plugin barcode scanner doesn't open the scan

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>

Phonegap Build - Crossplatform BarcodeScanner integration

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.

Phonegap/Cordova BarcodeScanner cordova.plugins undefined

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

barcodescanner phonegap plugin issue

I'm currently trying to implement barcodescanner in my phonegap project.
But I'm completly lost because I read a lot of topics about barecodescanner and all possible solutions provided didn't work for me.
First, some tutorials and documents says that I have to use
cordova.plugin.barcodeScanner.scan (...). But for me, cordova.plugin is always undefined.
Some others says that I have to do cordova.require("cordova/plugin/BarcodeScanner"); and it doesn't work, when I run my app, I get the following error : "module "cordova/plugin/BarcodeScanner" not found.
If you use PhoneGap Build... This is an example of implementation...
In the config.xml file add this line:
<!-- We'll include the Barcode plugin -->
<gap:plugin name="com.phonegap.plugins.barcodescanner" />
Then in the index.html file:
<script type="text/javascript">
function Scan() {
cordova.plugins.barcodeScanner.scan(
function (result) {
window.open(result.text,'_self', 'location=no') //Opens URL in browser
//alert("We got a barcode\n" +
// "Result: " + result.text + "\n" +
// "Format: " + result.format + "\n" +
// "Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
</script>
To call the script with a button in the body section of page:
<button onclick="Scan()">Barcode</button>
Good luck!

cordova.plugins undefined for cordova3.1

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.

Categories

Resources