Problems sharing combined text and image with SHARE INTENT on Twitter - android

I want to give the user the possibility to share a Image and a Text with Twitter and Facebook.
Actually my code can launch Android's share intent and if the user selects Facebook, all works fine, the Image is attached and the text is shown on the body of the new status.
But something is wrong with Twitter, if i only put a Image all works fine, the image is detected by twitter and automatically uploaded to twipic, then twitter posts the link of the image on the tweet. But if i put a image and a text, then, twitter doesn't detect the image and it only puts the text on the tweet, the image is ignored. What is wrong?
this is my code:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file:///sdcard/image.jpg");
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));

You can still try with ACTION_SEND, without using the ACTION_SEND_MULTIPLE.
ACTION_SEND_MULTIPLE resulted in a force close, when I tried to create new intents for sharing to Gmail, G+, etc.
This worked perfect for me:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri uri = Uri.parse("file:///sdcard/image.jpg");
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;

Specify MIME type also for the text. "text/plain" is the type of text data MIME. Try using "*/*" as MIME, so you can send any generic data type.
Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.
More info about ACTION_SEND_MULTPLE and handling MIME types:
http://developer.android.com/reference/android/content/Intent.html

Related

Share image puts path in to address

I'm having this issue where sharing an image from my app to Gmail puts the path of the image in the To field.
Here's the code that I'm using:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_SUBJECT,"Beam Dental Insurance Card");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
shareIntent.setDataAndType(insuranceCardImageUri, getActivity().getContentResolver().getType(insuranceCardImageUri));
shareIntent.putExtra(Intent.EXTRA_STREAM, insuranceCardImageUri);
startActivity(Intent.createChooser(shareIntent, "Share Insurance Card"));
And here's what I get.
The To: field gets filled in with the path to the image with the "content:" removed from the front. I've tried setting the EXTRA_EMAIL on the intent but that doesn't help.
First, replace:
shareIntent.setDataAndType(insuranceCardImageUri, getActivity().getContentResolver().getType(insuranceCardImageUri));
with:
shareIntent.setType(getActivity().getContentResolver().getType(insuranceCardImageUri));
as ACTION_SEND does not use a Uri in the data field of the Intent.
Then, remove:
shareIntent.setType("image/*");
as you do not need to call setType() twice (or even call setType() and setDataAndType(), as you have it here).
Also, bear in mind:
If the Uri is not coming from your app (e.g., your own ContentProvider), third-party apps like Gmail may not be able to use it, as they may not have permission to access it. This is not significantly different than passing a URL to a third-party app, where the URL requires an authenticated user session to be useful.
There is no requirement for ACTION_SEND implementations to honor both EXTRA_STREAM andEXTRA_TEXT`.
You can share image using share intent, but you've to decode image to a localized Bitmap
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image");
String path = Images.Media.insertImage(getContentResolver(), loadedImage, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
loadedImage is the loaded bitmap from http://eofdreams.com/data_images/dreams/face/face-03.jpg
acoording to Nitin Misra

How to send an image from url with ACTION_SEND intent to other app?

The image is an url, like http://www.example.com/123/abc.jpg
I want to share some text and an image with other app.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, String.format(getResources().getString(
R.string.share_text), pid));
intent.setType("image/jpg");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("http://www.example.com/123/abc.jpg"));
startActivityForResult(Intent.createChooser(intent, "Share with"),
Settings.SHARE_REQUEST);
But it is not work. It seems like the uri should be a local image? If this is true, how can I convert the image url to a local uri? Thanks!
See this page for details on sharing. You should not need to call startActivityForResult(). Just call startActivity() and it will properly prompt the user for where to send the data (i.e. pick Gmail, browser, etc.)

Is It possible to send an image and a text file, both using a single Intent in android?

The question is (might be a repeated one), but I could not find a proper answer to it, so asking here again.
In my application, I need to share both an image and a text file using a single intent.
I read a few answers, like:
ACTION_SEND sending both an Image and Text in the same Intent,
Send Image and Text both using ACTION_SEND or ACTION_SEND_MULTIPLE
and also Problems sharing combined text and image with SHARE INTENT
and tried to implement the given solutions in my application, but none of them worked for me.
The code I've implemented so far is as below :
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_SUBJECT, "I found movie "+movieTitle+" on Movies Tracker!");
share.putExtra(Intent.EXTRA_TEXT, "my text");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(share, "Share via"));
So now my question is: is there any way to share both an image and a text file with single intent?
If it's possible, then please help regarding this issue.
Thanks in advance.
try this one
private void initShareIntent(String type,String _text){
File filePath = getFileStreamPath("<span class="skimlinks-unlinked">shareimage.jpg</span>"); //optional //internal storage
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"));
}

android ACTION_SEND image and text

I want from my application to send to facebook and other applications an Image and some text so the user can share them. Currently I put the text and the image URI but when I choose facebook only the image is sent. In whatsApp also only the image is sent. In Google+ application both image and text are passed. Can someone show me the right direction?
Code example ( I don't have the original code here with me now, maybe I'll post it later)
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_TEXT , myText);
startActivity(Intent.createChooser(shareIntent, "Choose an app" ));
If I change ACTION_SEND to ACTION_SEND_MULTIPLE then it does not work at all. If I change type to "text/plain" or html then text is sent to whatsapp, google+ and Facebook messenger, but NOT in normal Facebook app ( it opens an empty share dialog).
You should use below lines
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/*");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My image");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename_toshare)));// this is for image . here filename_toshare is your file path.
sendIntent.putExtra(Intent.EXTRA_TEXT, "My Image ");// this is for text
startActivity(Intent.createChooser(sendIntent, "Email:"));
hope this helps you.

Android: Share Text & Image (URL) Via Intent

I am trying to share text with an image via an ACTION_SEND intent. The catch is that the image is represented by a URL, not a local URI. The code I currently have is:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, text); // <- String
shareIntent.putExtra(Intent.EXTRA_STREAM, url); // <- URL object
Now I've tried a few variations on this. I've tried with setType("image/*"), I've tried parsing a Uri from the URL, I've tried passing the URL string itself, etc. Nothing so far seems to work. However, when sending to twitter I do see the text, just not the image.
Edit:
Apparently the original description was not helpful enough, so....when I launch the above intent it successfully opens a chosen application like Twitter, or Facebook, or Gmail, or Text Messaging, but an image appars in NONE of these apps. The text appears in Twitter - I can't remember if the text appears elsewhere, but my focus at this moment is on the image part anyway.
You won't be able to share on Facebook in that way because of Facebook's policy as it says in a known bug:
API does not support pre-filling the message for users
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
sharingIntent.putExtra(Intent.EXTRA_TEXT,videoPos);
sharingIntent.putExtra(Intent.EXTRA_STREAM,getImageUri(getApplicationContext(), bitmap));

Categories

Resources