Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

cordova - Android Phonegap version 2.0 or higher any update for Share plugin for facebook , twitter, message etc

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...