【问题标题】:Phonegap - Share functionality to Email, Twitter and FacebookPhonegap - 将功能分享到电子邮件、Twitter 和 Facebook
【发布时间】:2010-12-31 14:51:38
【问题描述】:

是否有示例如何使用 Phonegap 框架编程功能以将 URL 共享到电子邮件、推特和 Facebook?例如,在 Android 中,90% 的应用程序都有此功能。在 Iphone 中,它在任何应用程序中。在 Iphone 的 techcrunch 应用程序中,当您打开一篇文章时,您可以看到它。是否也可以使用 Phonegap 来创建它?

【问题讨论】:

  • 你有没有想过这个问题,正在寻找一个适用于 ios/phonegap (cordova 1.7) 的简单解决方案

标签: twitter cordova


【解决方案1】:

您可以在 Android 中使用以下插件代码执行此操作。我还没有在其他任何地方发布它,但最终我希望将它作为插件添加到 Android 的 phonegap 插件存储库中。

JAVASCRIPT:

var Share = function() {};

Share.prototype.show = function(content) {
    return PhoneGap.exec(
    function(args) {
        console.log("phonegap share plugin - success!")
    }, function(args) {
        console.log("phonegap share plugin - failed")
    }, 'Share', '', content);
};

PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin('share', new Share());
    PluginManager.addService("Share","com.COMPANYNAME(CHANGEME).android.plugins.Share");
});

Android 中的 Java:

package com.COMPANYNAME(CHANGEME).android.plugins;

import org.json.JSONArray;
import org.json.JSONException;
import android.content.Intent;

import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;

public class Share extends Plugin {
    private String callback;

    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId) {
        PluginResult mPlugin = null;
        try {
            mPlugin = activateSharing(args.getString(0), args.getString(1));
        } catch (JSONException e) {
            Log.e("JSON Exception", e.toString());
        }
        mPlugin.setKeepCallback(true);
        this.callback = callbackId;
        return mPlugin;
    }

    private PluginResult activateSharing(String title, String body) {
        final Intent shareIntent = new Intent(
        android.content.Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);

        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx.startActivity(Intent.createChooser(shareIntent, "Share"));
        return new PluginResult(PluginResult.Status.OK);
    }
}

【讨论】:

    【解决方案2】:

    差不多三年后:这是一个允许在 Android 和 iOS 上使用相同 API 进行共享的插件。 https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin

    它也可以在 PhoneGap Build 上使用!

    例子

    window.plugins.socialsharing.share('Google is awesome, WOOT!', 'Google facts', 'https://www.google.com/images/srpr/logo11w.png', 'http://www.google.com');
    

    【讨论】:

      【解决方案3】:

      使用插件 appInBrowser 登录 Facebook 并发布提要、登录 Twitter 并发布状态:

      https://github.com/raulduran/facebook-twitter-cordova.git

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多