How share text with image on WhatsApp and Facebook via Share dialog?

345 Views Asked by At

I want to share text with image on WhatsApp and Facebook, I did for Whatsapp but the issue is in WhatsApp business because of package com.whatsapp and com.whatsapp.w4b but how to set both at once, and facebook only sent image not text, so to resolve the issue, please.

My code for sharing via WhatsApp, Facebook, and Twitter.

private void share(String text, Uri uri, int type) {
    Intent share = new Intent(Intent.ACTION_SEND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    share.setType("image/*");
    switch (type) {
        case 2:
            share.setPackage("com.whatsapp");
            break;
        case 3:
            share.setPackage("com.facebook.katana");
            break;
        case 4:
            share.setPackage("com.twitter.android");
            break;
        case 1:
        default:
            break;
    }
    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.putExtra(Intent.EXTRA_TEXT, text);
    startActivity(Intent.createChooser(share, "Select"));
}
1

There are 1 best solutions below

2
On

share.setPackage("pakagename");

is working for whatsapp and twitter but not for facebook so use facebook sdk .