Phonegap - 将功能分享到电子邮件、Twitter 和 Facebook [英] Phonegap - Share functionality to Email, Twitter and Facebook

查看:20
本文介绍了Phonegap - 将功能分享到电子邮件、Twitter 和 Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there an example how to program the functionality with the Phonegap Framework to share a URL to email, twitter and Facebook? For Example in Android this functionality is in 90% of the apps. In Iphone it is in any Apps. In the app of techcrunch for Iphone you can see it, when You open an article. Is it possible to create this with Phonegap too?

推荐答案

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

You can do this in Android with the following code for a plugin. I haven't published this anywhere else yet, but eventually I hope to add it as a plugin in the phonegap plugin repository for Android.

JAVASCRIPT:

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:

JAVA IN ANDROID:

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);
    }
}

这篇关于Phonegap - 将功能分享到电子邮件、Twitter 和 Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆