Skip to content

Instantly share code, notes, and snippets.

@matheusjardimb
Created December 18, 2014 11:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheusjardimb/eeb5c36dd16b5da3caeb to your computer and use it in GitHub Desktop.
Save matheusjardimb/eeb5c36dd16b5da3caeb to your computer and use it in GitHub Desktop.
Facebook Share Intent
public static void shareURL(Context context, String url) {
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.composer.shareintent.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", url);
context.startActivity(intent1);
} catch (Throwable e) {
// If native FB app is not installed, try share through SEND (browser or 3rd party apps)
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + url;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
context.startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment