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);
}
);
};
Related
I need to download huge file ( 160GB ) using my Cordova application. As file-transfer plugin was deprecated and suggested XMLHTTPRequest usage fails for huge failes, I downloaded cordova-plugin-background-download from https://github.com/sgrebnov/cordova-plugin-background-download. It works great for any iOS device, but it always fails on Android 13 with error
Unsupported path /storage/emulated/0/ ......
The error is when a temporary file is being crated. I assume, the problem is with this code:
this.setTempFileUri(Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory().getPath(),
Uri.parse(targetFileUri).getLastPathSegment() + "." + System.currentTimeMillis())).toString());
where
android.os.Environment.getExternalStorageDirectory().getPath()
returns invalid path.
Is there a workaround, how to make the plugin working on Android 13? I use the sample code from the plugin homepage on Github.
Line 114 of the src/android/BackgroundDownload.java file needs to be modified for proper functionality from
this.setTempFileUri(Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory().getPath(),
Uri.parse(targetFileUri).getLastPathSegment() + "." + System.currentTimeMillis())).toString());
to
this.setTempFileUri(Uri.fromFile(new File(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS),
Uri.parse(targetFileUri).getLastPathSegment() + "." + System.currentTimeMillis())).toString());
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'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.
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!
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.