I am trying to use the PhoneGap Share plugin for 2.0 version. I have implemented it but this is not work properly.
This plugin is written in PhoneGap 1.0 and later v
I am sharing my code which is working fine. Please refer This link for share plugin functionality and follow below given steps.
1- Place the JS file in the same folder of the MainActivity.java folder.
2- Place the Js file in the www folder and add it to the index.html folder.
3- Add the following line to the config.xml (if you are using new version of Phonegap) or plugins.xml (for old version of Phonegap):
4 - add html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/libs/cordova-2.0.0.js"></script>
<script type="text/javascript" src="js/libs/jq_min.js"></script>
<script src="js/libs/share.js">
</script>
<script>
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
}
//share plugin for update status
function share(subject, text) {
window.plugins.share.show({
subject: subject,
text: text},
function() {
alert("sent success");}, // Success function
function() {alert('Share failed')} // Failure function
);
};
//Send message on facebook
$(document).ready(function() {
$("button#sendFacebook").click(function(){
var txtsub = $("input#txtsub").attr("value");
var txtmsg = $("#txtmsg").val();
share(txtsub, txtmsg);
});
});
</script>
</head>
<body>
<input id="txtsub" type="text" placeholder="Enter Subject" maxlength="20" required /><br/><br/>
<textarea placeholder="Enter Message" id="txtmsg" rows="4" cols="25"></textarea><br/>
<button id="sendFacebook">Update Status </button>
</body>
</html>
and test this plugin for Face book,twitter,gmail etc. & enjoy :).
Let me know if you have any query.
it seems that you are not implementing the plugin in a proper way, just try the following steps:
1- Put the java file in the same folder of the MainActivity.java
2- Put the Js file in the www folder and add it to the index.html
3- Add the following line to the config.xml (if you are using new version of Phonegap) or plugins.xml (for old version of Phonegap):
<plugin name="Share" value="Path_Of_Your_Project.share.Share"/>
4- Just write the following into your JS file:
function share(subject, text) {
window.plugins.share.show({
subject: subject,
text: text},
function() {}, // Success function
function() {alert('Share failed')} // Failure function
);
};
To Call the function:
$("#share_id").onClick(function(){
share("subject", "text");
});
As simple as this.