Android Phonegap version 2.0 or higher any update

2020-02-05 05:57发布

问题:

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 version any new or updated plugin for share message on Facebook.

I've referred to this documentation and this question: How to implement facebook send, twitter share, send sms, send email in my phonegap android application?

But still not getting proper solution.

回答1:

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.



回答2:

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.