navigator.device UNDEFINED in PHONEGAP - CORDOVA - javascript

I am using PHONEGAP - CORDOVA.
Why do I get this error?
Uncaught TypeError: Cannot read property 'capture' of undefined
at this line:
navigator.device.capture.captureImage();
The project only imports cordova.js and index.js. I am just trying to open gallery on android with a simple button.
Should I import another file to this project?
Thanks!

In order for this to work you will need to add the Cordova media-capture plugin to your project as documented here.

Related

Cannot read property 'applicationDirectory in cordova

I am working on a Cordova application.
When I run the application for first time after installation, it works fine. But for subsequent runs it throws above error.
Added the cordova file transfer plugin
cordova plugin add cordova-plugin-file-transfer
Included the cordova script in my index.html
<script type="text/javascript" src="cordova.js"></script>
Using the app directory as below
alert(cordova.file.applicationDirectory);
Above line alerts or prints the path correctly when I run my application for the first time, soon after installation. But in the next runs I get the error "Cannot read property 'applicationDirectory' of undefined".
ANSWER IN BELOW COMMENTS
My issue fixed when I used the "file:///android_asset/www/Images/" instead of cordova.file.applicationDirectory+"/Images"

Ionic 2 / Cordova: Plugins Not Found

I seem to be having an issue with all Cordova plugins that I am adding to my project. For this question, I will reference specifically the SplashScreen plugin.
The process that I take when building my project for IOS is as follows:
ionic cordova platform add ios
ionoc cordova prepare ios
ionic cordova build ios
At this point, the build will fail with an error 65 on xcode args. After some googling, I found that a solution to this is to perform ionic cordova platform update ios, this fixes the problem and allows me to compile and run my application, yay!
The reason that I have included the above details is, I am worried that perhaps updating the platform is for some reason causing the plugins not to load / be included. Just a thought but thought I would include that process for reference.
When running my project in the IOS emulator on mac, I get the following plugin errors in the console for xCode, this error message is specifically for the StatusBar but is the same for all other plugins I have added:
2017-08-13 20:41:36.391 Shokuni[20906:1123728] CDVPlugin class CDVStatusBar (pluginName: statusbar) does not exist.
The plugins then reset due to page load…
2017-08-13 20:41:37.724 Shokuni[20906:1123728] Resetting plugins due to page load.
Then i get the following error about the status bar, which I assume is because it is being attempted to be used on the first page loaded in the project
2017-08-13 20:41:38.883 Shokuni[20906:1123728] CDVPlugin class CDVStatusBar (pluginName: StatusBar) does not exist.
2017-08-13 20:41:38.883 Shokuni[20906:1123728] ERROR: Plugin 'StatusBar' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
Inside xCode, in the File Explorer panel on the left, there are no plugins inside the plugin folder, I am wondering whether this could potentially be an issue? I can however see that the plugins that I have installed are available at staging/www/plugins
Anybody had this problem before or knows about what may be going on? If so I would be very grateful.

Adding Cordova Platforms

Hey, Guys! I recently started to work with Cordova and when I run the Cordova platform add android i get the following error. I have successfully placed the environment variables for Java and for the Android SDK as well. But the npm modules does not exist in C:/Windows/System32/npm as shown in the error, It is in the Users/My username/AppData/Roaming/npm folder. Some guidance would be appreciated.
I followed the following scripts which are shown in the official Cordova documentation to create a new project.
Cordova create hello com.example.hello HelloWorld
cd hello
Cordova platform add android -> where I'm stuck at
Kindly Check the Android Version Provided by Cordova and verify with your current Android version installed on your system , if there a mismatch :
1) Update Android Version From Android Studio SDK Manager
2) Update Cordova Platform - Refer: Cordova Documentation
External Source
cordova - Error: Failed to fetch platform android
I figured out halfway what the the problem was. There was a file named 'npm' in my C:/Windows/System32 directory wich was of 0kb size, and once i deleted it, the error vanished. But not all the way though. I was able to install the browser platform but not the android platform via cordova platform add android or even specifying what the matching cordova-andriod pluggin to be with cordova platform add andriod#version.
Only through the cordova platform add https://github.com/apache/cordova-android.git script I could install the andriod platform and once it was done other steps worked fine, and the project ran through the Android AVD. Any idea why the normal command to add the android platform didnt work, Just want to know but if it happens again i think Im gonna have to run the get from git command again. Thanks

How do I add ‘google-services.json’ file to a Meteor/Cordova project?

I'm trying to add a 'google-services.json' file to the Cordova project root folder as required by the cordova-plugin-fcm plugin (this plugin allows a receiving push notifications from Google Firebase). But because I'm using Meteor, the project root folder is not the same as the cordova root folder.
I've tried adding the file to both:
/<meteor project root>/cordova-build-override/google-services.json
/<meteor project root>/cordova-build-override/platforms/android/google-services.json
However I still receive the following error:
While adding plugin cordova-plugin-fcm#2.1.1 to Cordova project:
Error: cordova-plugin-fcm: You have installed platform android but file
'google-services.json' was not found in your Cordova project root
folder.
Its initiated by this file: https://github.com/fechanique/cordova-plugin-fcm/blob/master/scripts/fcm_config_files_process.js#L842
Any idea what I'm doing wrong?
Thanks in advance
Apparently this is a bug with the 2.1.1 version of cordova-plugin-fcm https://github.com/fechanique/cordova-plugin-fcm/issues/212.
I installed a different firebase plugin, cordova-plugin-firebase with my google-services.json file located at:
/<meteor project root>/cordova-build-override/google-services.json
and everything is now working as expected.

Cannot create Sencha Touch 2 jsb3 file, TypeError: 'undefined'?

Currently trying to set up and deploy a Sencha Touch 2 application. I'm following this guide: http://docs.sencha.com/touch/2-0/#!/guide/building
When I went to run sencha create jsb the response was:
TypeError: 'undefined' is not a function
phantomjs://webpage.evaluate():6
phantomjs://webpage.evaluate():1
C:\Program Files (x86)\SenchaSDKTools-2.0.0-beta3\compat\scripts\phantomjs-jsb.js:230
What's wrong? Is this a bug with the SDK tool?
Some tweaking of the app.json file fixed this problem. Not exactly sure what I did, but I went to build it again and it was fine.

Categories

Resources