Phonegap API not defined / Plugin error - javascript

I'm currently building an Application with PhoneGap(3.3). When i try to get the API to work i always get the error:
for example:
"Cannot call method 'vibrate' of undefined
What i did:
phonegap create appname com.myname.appname appname
phonegap local build android
phonegap plugin add XXXXXX plugin path (gave me response that plugin was installed correctly)
modified my index.html to call vibrate when the device is loaded
function onDeviceReady() {
navigator.notification.vibrate(2000);
}
But i still cant get the phonegap api to work since i get the error the method is not defined. Anybody got a solution for this or am i just plain dumb.
Regards

I would double check that you have installed both notification plugins:
cordova plugin add org.apache.cordova.dialogs
cordova plugin add org.apache.cordova.vibration
AND make sure that after you install the plugins you run the build command again:
phonegap local build android

Before deploying my code to native platforms, I often don't include links to the cordova.js and cordova_plugins.js. Make sure you've added those in before you prepare your code. It's an easy step to miss.

Related

File chooser to choose docx,pdf file from browsing local storage in phonegap cordova android application

I have tried these plugins for phonegap cordova android app
https://github.com/cdibened/filechooser
github.com/don/cordova-filechooser
but unable to install them in my application, getting error like this;
Error: Failed to fetch plugin https://github.com/cdibened/filechooser.git via registry.
I want to add functionality to upload pdf or doc file from phonegap to server but I unable to do that
I know there is a filetransfer plugin but it only allows me to browse media like image or videos but not document files.
Please, it would be great if anyone help me to do that
I'm stuck here.
I believe you are using Cordova Version 7 where is there is a major change related to fetch. You may check out more info on this official link
So you have to use the following command to install the plugin:
cordova plugin add https://github.com/cdibened/filechooser.git --nofetch
The --nofetch flag gives you the pre-Cordova#7.0 behavior
Thanks Gandhi for a reply but I tried that trick earlier but no succeed!
I have resolved this issue by adding this plugin finally, now I can choose a pdf from mobile local storage and upload it to the server using Filetransfer plugin,
If anyone want the source code , I will upload it here
Plugin link:
https://www.jsdelivr.com/package/npm/cordova-plugin-file-chooser
cmd: cordova plugin add cordova-plugin-file-chooser

How to get version of the other installed app on same device using Cordova?

I use lampa.startapp cordova plugin to know if apps are installed and to launch external apps on a device running my app (see: com.lampa.startapp).
navigator.startApp.check("com.application.name", function(message) { /* success */
console.log(message); // => OK
},
function(error) { /* error */
console.log(error);
});
But I need to know the version of another app installed on a device (not the current one) and this plugin does not seem to do this.
For example : I installed "myApp" Cordova app on a device. In these app, i want to check if "twitter" app is installed and if yes get "Twitter" version.
Does anyone know a method to get this app version?
To check if app is installed use AppAvailability plugin.
This plugin allows you to check if an app is installed on the user's device.
But it doesn't return app version, just whether it is installed or not.
To get application version you will probably need to write your own PhoneGap plugin.
There is also Cordova AppVersion plugin, but it only reads the version of your current app from the target build settings.
I found that if you install the plugin directly from the GitHub repo:
ionic cordova plugin add https://github.com/ohh2ahh/AppAvailability.git --save
the response to check() will come back with a JSON object that has the version information for that application you are checking on, instead of just a boolean that says whether it's there or not.
But you have to install it from the GitHub link, the npm link to the plugin doesn't appear to have that update to it.

Use node.js plugin in Cordova

I'm new to Cordova and am figuring out how to include a Node.JS Plugin, this one:
https://github.com/mateodelnorte/forecast.io
I've tried to include the JS file manually, but when running the code,
of course I get the error that "require is not defined".
After Googling I found out that I have to use Cordova package manager to install such plugins.
however,
there is no plugin for Forecast.io... So,
how to use this nodejs-plugin?
Do I need to create a Cordova plugin myself?

Android Phonegap 3.3.0 and Email Composer plugin Uncaught TypeError

I installed phonegap 3.3.0 via the command line, created app, added android platform OK. I can use the latest Android ADT to import phonegap app and test it on my Android device. Everything worked perfect.
I installed the Email Composer plugin https://github.com/katzer/cordova-plugin-email-composer via the command line
cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
The plugin seems install ok, however when I tried to run the javascript code
window.plugin.email.open();
I got error
Uncaught TypeError: Cannot call method 'open' of undefined:43
I put the email_composer.js inside js folder and in my index.html I add reference to it. Not sure why I get this error.
I already asked the author here https://github.com/katzer/cordova-plugin-email-composer/issues/9 and he answered:
You lead the plugin in the wrong way. Do not lead the plugins directly.
If you install a plugin through the command line interface,
they will be listed in the cordova_plugins.js file which is loaded
by cordova.js.
I looked up the file cordova_plugins.js I only saw these code:
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [];
module.exports.metadata =
// TOP OF METADATA
{}
// BOTTOM OF METADATA
});
I should see something about email_composer.js in this file, right? If so, then what I should write in here.
This is my first time using phonegap plugin, not sure what to do. Hope someone can help
Thanks
Always remember to 'prepare' your app after installing any new plugin. From the app's root:
cordova prepare android
This should update your cordova_plugins.js file
I found the bug. I got error if I call the javascript like this
window.plugin.email.open();
To make it works, call like this:
window.plugin.open();
(remove "email")
Hope this help someone

Phonegap version 3 phonegap.js not found

I have created a project in phonegap using version 3:
phonegap create -n SexDiaries -i co.uk.couplesdiaries
But when opening the index.html I get a network error that phonegap.js cannot be found, 404.
Why would they request a file that doesn't exist from the default build?
Where can I find this file?
The phonegap.js is not in the root for example:
projectname/www/phonegap.js
As you would expect, instead you need to first create a platform for the app to be build on, for example build the android platform with:
phonegap build android
Then, go inside the folder created:
platforms/android/assets/www
and then you'll see phonegap.js and all other things. It's very poorly documented :)
I'm adding a new answer because this SO post keeps coming up everytime I searched for "phonegap.js missing":
If you follow several guides out there you might see a reference to cordova build [platform]. With PhoneGap do not do this. Instead this is correct:
phonegap build [platform]
Then visit your platforms/[platform] directory.
I am developing a mobile app using html+css+jQuery mobile and i am building it using the phonegap web build service. The version of phonegap i am working on is 3.1.0.
I was trying to find how to use the Phonegap API on my mobile application and how to call the cordova methods (ex notification.alert). The solution to this is to just add the
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
inside the head of your index.html document. The Phonegap builder will find and include the correct cordova.js file for each build (Android, Win phone, iOS). If you will use the application on web then this script tag will always throw a 404 HTTP code.
Finally, the ondeviceready event is essential to any application. See the Full Example.

Categories