Reputation: 627
I am developing an application in which i have to share image and text on WhatsApp with in my application.
Is there any best way to do that.
I am capturing my application screen, and need to send that image via WhatsApp
Upvotes: 2
Views: 731
Reputation: 11565
After Spending some time I am able to share Image and Text to whatsapp from my application using this code :
String smsNumber = "91xxxxxxxxxx"; //without '+'
try {
Uri imageUri = null;
try {
imageUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(),
BitmapFactory.decodeResource(getResources(), R.drawable.whatsapp_image), null, null));
} catch (NullPointerException e) {
}
Intent shareIntent = new Intent("android.intent.action.MAIN");
shareIntent.setType("*/*");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "App - Link");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra("jid", smsNumber + "@s.whatsapp.net"); //phone number without "+" prefix
shareIntent.setPackage("com.whatsapp");
startActivity(Intent.createChooser(shareIntent, "send"));
} catch (Exception e) {
}
Happy Coding :)
Upvotes: 1