package com.barefootcoders.android.react.KDSocialShare;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.Callback;

import java.util.List;
import java.io.File;

public class KDSocialShareModule extends ReactContextBaseJavaModule {
  ReactApplicationContext reactContext;

  public KDSocialShareModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
  }

  @Override
  public String getName() {
    return "KDSocialShare";
  }

  @ReactMethod
  public void tweet(ReadableMap options, Callback callback) {
    try {
      String shareText = options.getString("text");
      Intent shareIntent;

      if (doesPackageExist("com.twitter.android")) {
        shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setClassName("com.twitter.android", "com.twitter.android.PostActivity");
        shareIntent.setType("text/*");
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
      } else {
        String tweetUrl = "https://twitter.com/intent/tweet?text=" + shareText;
        Uri uri = Uri.parse(tweetUrl);
        shareIntent = new Intent(Intent.ACTION_VIEW, uri);
      }
      reactContext.startActivity(shareIntent);
    } catch (Exception ex) {
      callback.invoke("error");
    }
  }

  private boolean doesPackageExist(String targetPackage) {
    PackageManager pm = this.reactContext.getPackageManager();
    try {
      PackageInfo info = pm.getPackageInfo(
        targetPackage,
        PackageManager.GET_META_DATA
      );
     } catch (PackageManager.NameNotFoundException e) {
       return false;
     }
     return true;
  }
}

@@ -1696,16 +1696,743 @@
  %7D%0A  %7D%0A%0A
+  @ReactMethod%0A  public void shareOnFacebook(ReadableMap options, Callback callback) %7B%0A    try %7B%0A      String shareText = options.getString(%22text%22);%0A      String shareUrl = options.getString(%22link%22);%0A      Intent shareIntent;%0A%0A      if (doesPackageExist(%22com.facebook.katana%22)) %7B%0A        shareIntent = new Intent(Intent.ACTION_SEND);%0A        intent.setType(%22text/plain%22);%0A        intent.putExtra(Intent.EXTRA_TEXT, shareText);%0A      %7D else %7B%0A        String sharerUrl = %22https://www.facebook.com/sharer/sharer.php?u=%22 + shareUrl;%0A        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));%0A      %7D%0A      reactContext.startActivity(shareIntent);%0A    %7D catch (Exception ex) %7B%0A      callback.invoke(%22error%22);%0A    %7D%0A  %7D%0A%0A
   privat

Add rudimentary support for Facebook sharing via Android