是否有一个示例如何使用Phonegap Framework对功能进行编程以共享电子邮件,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");
});
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
将近三年后:这是一个允许在 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');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10235 次 |
| 最近记录: |