(Android) Share PNG from Drawable folder direct to WhatsApp - android

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"));

Related

Send WhatsApp Stickers programmatically

I'm working on an app in Android that needs to open a WhatsApp conversation with a previously chosen sticker.
Maybe is there a way to do it like when a picture is sent, like this:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("image/*");
sendIntent.putExtra("jid", numero + "#s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.putExtra(Intent.EXTRA_STREAM, filepath);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);

Send a text message for a specific number using WhatsApp

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

How to share application link via message share application

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"));
}

Is it possible to put a string resource in EXTRA_TEXT

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);

Open Share Dialog to Share a File USing ACTION_SEND

I know how to share A text using ACTION_SEND.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Download Link https://play.google.com/store/apps/details?id=com.mtracker2051");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share This App"));
I want to share a text file using the ShareDialog.
How can I do it.
I read about this here http://developer.android.com/training/sharing/send.html but cound not get much from this link.
String fileName = ...
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"Share File"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "File Name");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileName)));
startActivity(Intent.createChooser(emailIntent, "Share File"));

Categories

Resources