2010-12-31 5 views
14

Gibt es ein Beispiel, wie man die Funktionalität mit dem Phonegap Rahmen programmiert, um eine URL zu email, Twitter und Facebook zu teilen? Zum Beispiel in Android ist diese Funktionalität in 90% der Apps. In Iphone ist es in allen Apps. In der App von techcrunch für Iphone kann man es sehen, wenn man einen Artikel öffnet. Ist es möglich, dies auch mit Phonegap zu erstellen?Phonegap - Teilen Sie Funktionalität zu E-Mail, Twitter und Facebook

+0

Haben Sie jemals das herauszufinden, für eine einfache Lösung, die für Arbeiten ios/Phonegap (Cordova 1.7) – nate8684

Antwort

7

Sie können dies in Android mit dem folgenden Code für ein Plugin tun. Ich habe dies noch nirgendwo anders veröffentlicht, aber ich hoffe, dass ich es als Plugin im phonegap plugin repository für Android hinzufügen kann.

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

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

Fast drei Jahre später: Hier ist ein Plugin, das auf Android und iOS mit der gleichen API ermöglicht die gemeinsame Nutzung. https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin

Sie ist auch auf PhoneGap Build verfügbar!

Beispiel

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