0

I want to share images from my application to Whatsapp but I am not able to do this. I place all images into assets folder. What do I have to change?

public void onClickWhatsApp() {

        Intent waIntent = new Intent(Intent.ACTION_SEND);
        waIntent.setType("text/plain");
                String text = "Hey, check out this cool game for Android ‘Free Ticket Bollywood Quiz’ www.globussoft.com";
        waIntent.setPackage("com.whatsapp");
        if (waIntent != null) {
            waIntent.putExtra(Intent.EXTRA_TEXT, text);//
            startActivity(Intent.createChooser(waIntent, "Share with"));
        } else {
            Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
                    .show();
        }
}
user1725145
  • 3,993
  • 2
  • 37
  • 58
user3048165
  • 65
  • 12

1 Answers1

3

Your title is about sharing image, but you try sharing text. Well. try any of these.

Try this to share text:

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "This is a test text");
try {
    activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
    ToastHelper.MakeShortText("Whatsapp have not been installed.");
}

Try this to share image:

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
Uri uri=Uri.parse("file:///android_asset/myimage.png"); 
whatsappIntent.setType("image/*");
whatsappIntent.setPackage("com.whatsapp");
sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
try {
    activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
    ToastHelper.MakeShortText("Whatsapp have not been installed.");
}

Hope it helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124