Android - How to use ShareGap Share Plugin

I'm trying to use the PhoneGap Share plugin, which should open my own Android “Share” window, which allows the user to choose which application to share.

https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share

I have a hyperlink that 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 I try to debug the application on my phone, I get the following error:

Unable to call the 'show' method from undefined in file: ///android_asset/www/index.html

What do I need to do to get this to work?

+8
javascript android cordova
source share
4 answers

Today I faced the same problem. I did this using the following code, not 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 ); 
+9
source share

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
    i.e. src \ com \ schaul \ plugins \ share \ Share.java

  • In index.html , call the following code after downloading the phonegap.1.2.0.js and share.js file:

Call the code mentioned by Peter ...

 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 that it works ...

+3
source share

Use the updated version for cordova 2.7 and higher from

https://github.com/robincharummoottil/phonegap-plugins/tree/master/Android/Share

+1
source share

The error tells you that the window.plugins object does not have a "share" property.

Make sure you follow the steps to install the sharing plugin and add the download of the share.js file to your index. html, something that the installation steps are omitted to tell you.

0
source share

All Articles