I'm trying to open WhatsApp with both text message and phone number, the phone number is OK but the message are not being displayed
Here's my code:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.SetComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.SetType("text/plain");
sendIntent.PutExtra("jid", phone_number + "#s.whatsapp.net");
sendIntent.PutExtra(Intent.ExtraText, "extra_text test");
sendIntent.PutExtra("sms_body", "sms_body test");
sendIntent.PutExtra("body", "body test");
sendIntent.PutExtra("text", "text test");
context.StartActivity(sendIntent);
I've tried all these "PutExtra" options but it's not working.
Thanks in advance!
What they allow via Intent extras is limited.
C# Example:
var sendIntent = new Intent();
sendIntent.SetPackage("com.whatsapp");
sendIntent.SetAction(Intent.ActionSend);
sendIntent.PutExtra(Intent.ExtraText, "StackOverflow.");
sendIntent.SetType("text/plain");
StartActivity(sendIntent);
Ref: https://www.whatsapp.com/faq/android/28000012
For my application, I would like to give share option.
For this, I have edit text to give phone number and a share button. If user gives a valid number and clicks share button, list of all available message sending application should list. If user selects an application from the list then a message with the application link should send his phone using the selected application.
How can I implement this? Please help.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "message link");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Chooser title text"));
try this
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,"your application link"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
Try Below code,This is exactly that you want ,
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, Your_EditText_object.getText().toString());
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Your Title"));
Try this:
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(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
References link:
https://developer.android.com/training/sharing/send.html
public static void callShare(Context theCtx, String theImagePath, String theText)
{
// Pass the message and Image path that you want to share
File myImageFile = new File(theImagePath);
String shareBody = theText; //"Here is the share content body " ;
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
if (myImageFile.exists()) {
// email address is required to be filled.
sharingIntent.setType("image/jpeg");
// "file://" and .getAbsolutePath is very important for Extra_Stream.
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
} else if (!theText.isEmpty()) {
sharingIntent.setType("text/*");
}
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
How can I do Action.SEND with Intent to show only facebook app(or to open it at once)?
I did it for all app witg Action.SEND:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Test text");
sendIntent.setType("text/plain");
startActivity(sendIntent);
I found the code for sharing text directly to WharsApp from my app:
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);
sendIntent.setPackage("com.whatsapp");
Now I want to share a PNG from my Drawable folder (R.drawable.image2share) directly to WhatsApp. How do I do that?
Try this:
Uri imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/image2share");
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sendIntent.setType("image/png");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendIntent.setPackage("com.whatsapp");
startActivity(Intent.createChooser(sendIntent, "send"));
I have this line that I share the text "text to share"
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "text to share");
sendIntent.setType("text/plain");
startActivity(sendIntent);
but I want to share a #string no "text to share"
You can just use getResources() method to get access to your resources and then use getString():
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.text_to_share));
sendIntent.setType("text/plain");
startActivity(sendIntent);