I wanted to know how I can send text and image to a specific whatsapp contact. I found some code to view a specific contact, but not to send data.
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", smsText);
i.setPackage("com.whatsapp");
startActivity(i);
But that code just opening the chat history, but doesn't take the text and image and send it.
I also try the below code for send image and text via whatsApp but that ask for choose the contact for send
Intent shareIntent = new Intent();
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, sendString);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent. setPackage ("com. whatsapp");
startActivity(shareIntent);
If that functionality is possible then please give me a suggestion for this.
Solution :
Intent sendIntent = new Intent("android.intent.action.SEND");
File f=new File("path to the file");
Uri uri = Uri.fromFile(f);
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.ContactPicker"));
sendIntent.setType("image");
sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("919xxxxxxxxx")+"#s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT,"sample text you want to send along with the image");
startActivity(sendIntent);
Refer to my answer at for detailed explanation.
https://stackoverflow.com/a/41805567/3989718
Related
Is some one knows how can i share image or file via my application with text to whatsapp member?
String text = "Look at my`enter code here` awesome picture";
Uri pictureUri = Uri.parse("file://my_picture");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, myPicUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));
I tried this one and it works great for any file that ends in .txt
It is great, but i just want to add an extra text to this message
Is it possible?
I am trying to launch whatsapp app from my app and passing some text to a particular number. Whatsapp App is launching and but text is not able to pass.
String smsNumber = "98*******3";
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, textWithClickableLink);
i.setPackage("com.whatsapp");
mContext.startActivity(i);
Is there anything missing in my code?
Please help me on this.
Thanks in advance!
Try this one:
Uri uri = Uri.parse("smsto:" + mobileno);
Intent whatsappIntent = new Intent(Intent.ACTION_SENDTO, uri);
whatsappIntent.setPackage("com.whatsapp");
String str = "https://play.google.com/store/apps/details?id=com.example.activity&hl=en";
whatsappIntent.putExtra("sms_body", str);
try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
// Whatsapp have not been installed
}
you can try this method, it should work. I have tested
private void shareWhatsApp() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "text to share");
//if you have any images to share sue this, uri is the uri of image
//shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
//shareIntent.setType("image/*"); for image sharing
shareIntent.setType("text/plain");
shareIntent.setPackage("com.whatsapp");
startActivity(shareIntent);
}
This will launch WhatsApp application and you have to manually select the contacts and send. since they dont provide any SDK we cant send automatically.
I tried this code. It makes my app to open list of all app by which I can send messages. After selecting any app now I am able to send the message that I am attaching with intent.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "From Stockal App");
intent.putExtra(Intent.EXTRA_TEXT, text);
mContext.startActivity(intent);
Thank you all for your response.
I wanted to make a share button on a Navigation drawer, when the user touches the button it will open up that black drawer with the list of all applications and the user can share the apps Google play link. Is there any generic code template? the only answers I have found is to just share it on one application such as Facebook which seems useless because not everyone uses Facebook.
Use share intent http://developer.android.com/training/sharing/send.html
sample code
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
You can send content by invoking an implicit intent with ACTION_SEND.
To send images or binary data:
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));
send an image along with text. This can be done with:
String text = "Look at my awesome picture";
Uri pictureUri = Uri.parse("file://my_picture");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));
Sharing multiple images can be done with:
Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
Here is the Kotlin version
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)
I am using share intent to post the image and text in Social media App. I am using following code
String shareName=advdetails.get(0).getBusinessname();
String description=advdetails.get(0).getDescription();
Uri image = Uri.parse(advdetails.get(0).getBusinesslogo());
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, description);
shareIntent.putExtra(Intent.EXTRA_STREAM, image);
startActivity(Intent.createChooser(shareIntent, shareName));
The above description, image and ShareName are getting from the pojo class.
When I am trying to share these data into Facebook, I am getting the information as "One or more Media items could not be added"
Try this to share image
File filePath = getFileStreamPath("shareimage.jpg");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, _text);
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath))); //optional//use this when you want to send an image
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
I have my images in drawable folder and I am getting that images in gridview.Also I am showing the perticular image on selection fullscreen.Now I want to send MMS with image attachment.
Here is my code to show the image. And to send MMS.how to get Uri to put to intent or how to send the image attachment.
imageView.setImageResource(imageAdapter.mThumbIds[position]);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "Hii");
sendIntent.setType("image/png");
startActivity(sendIntent);
Use the following code to send the mms.. Hope this wil help you.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hi how are you");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/file.gif")));
intent.setType("image/gif");
startActivity(Intent.createChooser(intent,"Send"));
Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");
EDIT:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hi how are you");
Uri uri = Uri.parse("android.resource:// com.example.stack/drawable/ic_launcher.png");
intent.putExtra(Intent.EXTRA_STREAM,uri );
intent.setType("image/png");
startActivity(Intent.createChooser(intent,"Send"));