I am trying to use the PhoneGap Share plugin which is supposed to bring up the native Android "Share" window which allows the user to pick which application to share to.
I have a hyperlink which calls the following code (provided on github).
window.plugins.share.show({
subject: 'I like turtles',
text: ''
},
function () {}, // Success function
function () {
alert('Share failed')
} // Failure function);
When trying to debug the app on my phone, I get the following error:
Cannot call method 'show' of undefined at file:///android_asset/www/index.html
What do I need to do to get this to work?
I am trying to use the PhoneGap Share plugin which is supposed to bring up the native Android "Share" window which allows the user to pick which application to share to.
https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share
I have a hyperlink which calls the following code (provided on github).
window.plugins.share.show({
subject: 'I like turtles',
text: 'http://www.mndaily.com'
},
function () {}, // Success function
function () {
alert('Share failed')
} // Failure function);
When trying to debug the app on my phone, I get the following error:
Cannot call method 'show' of undefined at file:///android_asset/www/index.html
What do I need to do to get this to work?
Share Improve this question edited Jul 16, 2012 at 20:02 Daniel Li 15.4k6 gold badges44 silver badges60 bronze badges asked Nov 29, 2011 at 4:27 Doctuh D.Doctuh D. 3951 gold badge7 silver badges18 bronze badges4 Answers
Reset to default 9I have faced the same problem today. I made it work using the following code instead of the window.plugins thing:
var share = new Share();
share.show({
subject: 'I like turtles',
text: 'http://www.mndaily.com'},
function() {}, // Success function
function() {alert('Share failed')} // Failure function
);
This is what you can do...
Add to
plugins.xml
:<plugin name="Share" value="com.schaul.plugins.share.Share"/ >
Save
share.js
to\assets\www\
From
index.html
, call<script type="text/javascript" charset="utf-8" src="share.js" ></script>
Add
Share.java
to\src\com.schaul.plugins.share
that is: src\com\schaul\plugins\share\Share.javaIn
index.html
, call the following code after the phonegap.1.2.0.js and share.js files are loaded:
Call the code that Petroy mentioned...
var share = new Share();
share.show({
subject: 'I like turtles',
text: 'http://www.mndaily.com'},
function() {}, // Success function
function() {alert('Share failed')} // Failure function
);
Let us know it works...
Use updated version for cordova 2.7 and above from
https://github.com/robincharummoottil/phonegap-plugins/tree/master/Android/Share
The error tells you that the object window.plugins does not have a "share property".
Check that you followed the installation steps of the share plugin, and that you added the loading of the share.js file in your index.html, something the installation steps omits to tell you.