window.plugins undefined when trying to use the phonegap plugins on android - android

I can't load the plugins in android. I have added the plugin to the plugins.xml list, have added the java code in my project. But still when I call window.plugins I get undefined object. Why is this happening? BTW I'm trying to use the share plugin - https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share
Just to be clear, I have added the phonegap.js file and the share.js file containing the JS plugin code. Also I have used the EmailComposer plugin for iphone with same code and it works on iphone, i.e. on iphone the window.plugins object it isn't undefined.

I fixed the exact same issue after noticing... i forgot to reference phonegap-1.1.0.js in my html. I also had to uncomment PhoneGap.addPlugin('share', new Share()); in share.js.

I had the same issue and I think I found the problem with phonegap.
You should go see on this thread, it may explain why you can't access your plugins : Phonegap background geolocation plugin not found

In phonegap 1.1.0 we can't call the windows.plugin what we need to in your share.js instead of
PhoneGap.addConstructor(function() {
});
add navigator.your plugins.js=new WebIntent(); (Java file) and call the plugin as navigator.your javascript plugin name in your javascript.

Related

sendJavascript doesn't works in InAppBrowser (migration from Cordova 2.7 to 3.6.4)

When I finished the migration, CordovaActivity.sendJavascript was marked as deprecated.
I call this method from an InAppBrowser Cordova Plugin and with 2.7 works but in Cordova 3.6.4 don't.
Console shows:
Set native->JS mode to null
How should i call sendJavascript in Cordova 3.6.4? What is the replacement for this deprecated method?
Thanks
First of all, you shouldn't use cordova plugins inside InAppBrowser, InAppBroser should be used just to display external websites without leaving your app
Anyway, you can execute javascript from the native part using this:
String js = "alert('test')";
yourInAppBrowserWebView.loadUrlNow("javascript:" + js);

how to use clipboard plugin with a phonegap build app

Has anyone gotten the clipboard plugin to work with "PhoneGap Build"?
I can't get it to work. I'm currently useing phonegap 3.1.0
My app is for android and IOS. I've only tested the clipboard plugin on android so far, and it isn't working.
in my config.xml:
<gap:plugin name="com.verso.cordova.clipboard" />
in my javascript:
window.plugins.clipboard.copy('some text',function(){alert('success');},function(response){alert('error:' + response);});
window.plugins.clipboard.paste(function(text){alert('paste success:' + text);},function(response){alert('paste error:' + response);});
The way I have it above, the script runs, but for both the copy and paste calls, the error function is executed and the response is "Class not found".
I have tried the above call window.plugins.copy, cordova.plugins.copy
both of those just cause the script to abort.
phonegap is loading just fine and the deviceready function has already fired before I attempt the above calls.
Under the plugins tab on the phonegap build webpage for my app:
Installed 3rd Party Plugins
com.verso.cordova.clipboard 0.1.0
This appears to be unrelated to the copy/paste plugin. In phonegap 3.1 you have to reference all the phonegap plugins you want to use. In this case, I'm guessing you have a function that checks if the user has an internet connection? If so, you need to add to your config.xml

Phonegap 3 - Call Cordova methods in hosted application

I'm porting a Phonegap 2.7 application to Phonegap 3. The application is hosted, so phonegap loads an external url instead of a local html. This hosted webapp loads cordoba.js, however I'm unable to use plugins such as splashscreen and notifications from the hosted webapp:
navigator.splashscreen.hide();
// Uncaught TypeError: Cannot call method 'hide' of undefined
navigator.notification.vibrate(500);
// Uncaught TypeError: Cannot call method 'vibrate' of undefined
The hosted application required the same Cordova file that was included when I created the Phonegap 3 project. Why am I unable to use this API's? This worked fine on Phonegap 2.7.
UPDATE: Events are triggered correctly:
document.addEventListener('deviceready', callback, false);
callback is correctly called, so there is some kind of cordova interaction already. Problem seems plugins.
Call the plugin directly with cordova.exec. it goes like this:
cordova.exec(function(response){}, function(errorText){}, "PluginName", "method", []) ;
Cordova exec()!
I wonder if your cordova.js file just doesn't have the navigator.splashscreen object. In Cordova 3.0, all of the plugins were separated out, and the cordova.js file just became the bridge code. When the app runs, it loads all of the plugin .js files via ajax - see the cordova_plugins.js file in a built project. As it loads these files, Cordova will fix up the namespaces for you, so that navigator.splashscreen namespace actually maps to the splashscreen js code. I'm betting you are not loading this cordova_plugins.js file which means the clobbering isn't working.
It's still working because the bridge code works. When you use exec() you're just running the command that navigator.splashscreen.hide does: https://github.com/apache/cordova-plugin-splashscreen/blob/master/www/splashscreen.js#L26
If I were you, I'd try to rebuild the app the new Cordova 3.x way, with the cordova cli. That way you won't have to actually call the exec function manually which seems pretty brittle (the exec() probably won't change, but it seems like a pain looking up the exec calls for every plugin interaction you need.)
BTW I'm not sergio on irc, so feel free to give him the answer if he posts since he answered your question first. I'm just trying to explain why that happens and why it doens't work for you anymore - basically, 2.7 and 3.x are pretty different in terms of plugins.

Android: Phonegap 3.1.x fail to load geolocation plugin

We are using Phonegap 3.1.0-0.15.0 and the application chocked when trying to access location information.
Works fine in iOS however the App chock on Android
We are using:
navigator.geolocation.getCurrentPosition(app.location.onSuccess, app.location.onError);
and we also tried:
var geo = cordova.require('cordova/plugin/geolocation');
geo.getCurrentPosition(app.location.onSuccess, app.location.onError);
The logcat mentioned the following:
Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1511
Uncaught module cordova/plugin/geolocation not found at file:///android_asset/www/phonegap.js:56
The plugin was added using:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
Are we doing something wrong ?
Thank you in advance
/Edwardo.
Just to answer my own questions. I removed all the plugins manually and then add them (including the problematic geolocation plugin) using the following command:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
That solved my issue.
Edward.

Date picker plugin is not working on cordova 2.2.0?

I am creating a android app using cordova 2.2.0.Now i am geting error on datepicker plugin.
I installed date picker plugin refer this link https://github.com/phonegap/phonegap-plugins/tree/master/Android/DatePicker.
Now i get Uncaught TypeError: Cannot read property 'datePicker' of undefined.
Please guide me.
Thanks for your help.
Make sure that you placed the DatePickerPlugin.java in the correct package. They recently updated the plugin's Java file to match the new CordovaPlugin class, but forgot to update the README.
DatePickerPlugin.java should be in a package named com.phonegap.plugins (notice the s at the end.)
Then in your config.xml, you should have <plugin name="DatePickerPlugin" value="com.phonegap.plugins.DatePickerPlugin"/>, again, notice the s in plugins.
Additionally, I noticed in the README that they do not tell you to include the .js file in your HTML page. If you want to actually use the plugin, make sure that you add this into your HTML page: <script type="text/javascript" charset="utf-8" src="datePickerPlugin.js"></script>. This is actually probably your problem based on that error message.

Categories

Resources