Android Phonegap 2.0或更高版本的facebook, twitter, message等共享插件的任何



我正在尝试使用2.0版本的PhoneGap共享插件。我已经实现了它,但这是不正常工作。

这个插件是写在PhoneGap 1.0和更高版本的任何新的或更新的插件在Facebook上分享消息。

我已经提到了这个文档和这个问题:如何实现facebook发送,twitter共享,发送短信,发送电子邮件在我的phonegap android应用程序?

但仍然没有得到合适的解决方案。

我正在分享我的代码,这是工作良好。请参考这个链接分享插件的功能,并按照下面给出的步骤。

1-将JS文件放在MainActivity.java文件夹的同一个文件夹中。

2-将Js文件放在www文件夹中,并将其添加到index.html文件夹。

3-在config.xml(如果您使用的是新版本的Phonegap)或plugins.xml(对于旧版本的Phonegap)中添加以下行:

4 -添加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>

和测试这个插件的脸书,推特,gmail等。,享受:)。

如果你有任何疑问请告诉我。

似乎你没有以适当的方式实现插件,只是尝试以下步骤:

1-将java文件放在MainActivity.java

的同一个文件夹中

2-把Js文件放到www文件夹中,并添加到index.html

3-在config.xml(如果您使用的是新版本的Phonegap)或plugins.xml(对于旧版本的Phonegap)中添加以下行:

<plugin name="Share" value="Path_Of_Your_Project.share.Share"/>

4-只需在JS文件中写入以下内容:

function share(subject, text) { 
  window.plugins.share.show({
    subject: subject,
    text: text},
    function() {}, // Success function
    function() {alert('Share failed')} // Failure function
  );
};  

调用函数:

$("#share_id").onClick(function(){
   share("subject", "text");
});

就这么简单。

最新更新