I know this question has been asked many times and in many different ways (see here and here). However, I haven't been able to achieve it in the following way:
The picture and the title are in the same section. Then, there is the rest with the link in another section. I have achieved to put text and image together, but the picture is on the top of the text.
This is the code I am using:
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, shareContentByWhatsapp(contentType));
intent.putExtra(Intent.EXTRA_STREAM, getImage());
intent.setType("image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Does anyone know how to obtain same result than in the picture?
As image you have shared,
In this case you just need to share the link,
image and link related content will be fetched by WhatsApp itself.
You can do like this:
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
mContext.startActivity(whatsappIntent);
or, you can share image with caption.
But, image you have shared, is whatsapp's functionality :-)
Related
I want to share multiple images with a single text on Whatsapp.
I am using this code
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_TEXT, "Text caption message!!");
intent.putExtra(Intent.EXTRA_HTML_TEXT, "<html>Text caption message!!");
intent.setType("text/plain");
intent.setType("image/jpeg");
intent.setPackage("com.whatsapp");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);
This code is working fine but the problem is that the text is coming on every image. I want the text to be placed on only one image. Is there any way I can do that? TIA
I need to share text and one image from my application via a share intent. I read this article. I thought it would be easy to create share intent. But it is not so easy, because there is a problem with sharing via Facebook.
I need to share some text and one image, which is stored in device. My first attempt looked like this:
The first try
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/img.jpg")));
shareIntent.putExtra(Intent.EXTRA_TEXT, "My custom text...");
shareIntent.setType("image/jpg");
startActivity(Intent.createChooser(shareIntent, getString(R.string.label_share)));
I tried this code and in applications like Gmail, Google+, Google Keep, etc, everything works fine. But Facebook did not work fine.
There is no my text ("My custom text...") in this screenshot. So I have tried something else.
The second try
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/img.jpg")));
shareIntent.putExtra(Intent.EXTRA_TEXT, "My custom text...");
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, getString(R.string.label_share)));
And the result of this is here:
There is no text and also no image in this screenshot.
I also tried to change type to image/* and */*, but it did not help. I do not know what is wrong. I just need to share some text and image via Facebook. The first try works well for other applications, but for Facebook not.
Can someone help me, please?
Your first attempt is OK, Facebook does not allow sharing text this way, they say "Pre-filling these fields erodes the authenticity of the user voice."
I could understand from various post that it is not possible to share both the image and text data in Facebook through intent share. But Twitter is able to share both thumbnail and text in Facebook through intent share which is shown in the image. SO can u comment on this and suggest a way to share both image and text in Facebook through intent.
Thanks in advance.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, viewProject.getShareLink());
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "compatible apps:"));
I put a button to share my Android app on Facebook, so I wrote the following code
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
// add the app link
intent.putExtra(Intent.EXTRA_TEXT, "http://play.google.com/store/apps/details? id=com.phonelight.realparrot");
startActivity(Intent.createChooser(intent, "Share with Facebook"));
After sharing, I opened my Facebook account and saw the following:
As you can see, It should be an image in the right square. I am wondering how can I put that image, I am thinking to put my icon app
Like if you share a youtube link, the image will be the first shot of the movie.
Change intent.setType("text/plain");
to intent.setType("image/*");
then add intent.putExtra(Intent.EXTRA_STREAM, myImageContentUri);
So I would like to do something like:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(myMessageAsImage));
intent.putExtra(Intent.EXTRA_TEXT, "My Message");
intent.setType("text/plain"); // or intent.setType("image/<imageType>");
However the documentation for ACTION_SEND doesn't seem to make this seem possible. Is there an agreed upon way to do this?
I don't know what you mean by 'common way' but I think you should set the type to intent.setType("image/*");.
EDIT:
How you send data with intent depends on the availability of apps that filter your particular action. Apps that handle ACTION_SEND may not handle ACTION_SEND_MULTIPLE. Clicking Share on HTC Gallery produces a list of applications that handle image, single or multiple. If you choose Mail then you can select multiple images. But if you choose Facebook or Peep then you can only select one image. This is my simple solution if you want to do the reverse of HTC Gallery, that is: user chooses image(s) first then you show him all compatible apps based on how many he selected.
// assuming uris is a list of Uri
Intent intent = null;
if (uris.size > 1){
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
} else if (uris.size() == 1) {
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));}
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, "Some message");
startActivity(Intent.createChooser(intent,"compatible apps:"));