twitter - Phonegap - 将功能分享到电子邮件、Twitter 和 Facebook

标签 twitter cordova

是否有示例如何使用 Phonegap 框架对功能进行编程以共享电子邮件、Twitter 和 Facebook 的 URL?例如,在 Android 中,90% 的应用程序都具有此功能。在 iPhone 中,它位于任何应用程序中。在 iPhone 的 techcrunch 应用程序中,当您打开一篇文章时,您可以看到它。是否也可以使用 Phonegap 创建这个?

最佳答案

您可以在 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);
    }
}

关于twitter - Phonegap - 将功能分享到电子邮件、Twitter 和 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4570701/

相关文章:

javascript - 我可以在不显示 webview 的情况下使用 phonegap 吗?

android - Sencha Touch 2.3/Cordova : Build run directly on device

android - 我无法为 Eclipse 安装 PhoneGap 插件

javascript - jquery mobile Phonegap应用程序中的canvas加倍

html - 推特 + HTML5 webSocket API

Java twitter OAuth,无法验证 oauth 签名

python - 如何在 Twitter 数据的 Pandas 数据框上应用 NLTK word_tokenize 库?

ruby-on-rails - 尝试让 twitter_auth api 工作..没有加载此类文件(LoadError)

android - 无法使用 twitter4j 授权我的应用程序

visual-studio - 无法在 vs 2017 中调试问题 Apache cordova 项目