Android share intent for facebook- share text AND link

I just built this code and it’s working for me:

private void shareAppLinkViaFacebook(String urlToShare) {
    try {
        Intent intent1 = new Intent();
        intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
        intent1.setAction("android.intent.action.SEND");
        intent1.setType("text/plain");
        intent1.putExtra("android.intent.extra.TEXT", urlToShare);
        startActivity(intent1);
    } catch (Exception e) {
        // If we failed (not native FB app installed), try share through SEND
        String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
        startActivity(intent);
    }
}

Leave a Comment