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."
Related
I'd like to share different information depending on the application selected by the user. For example, I'd like to send shorter text to Twitter than I do Gmail (otherwise, I go over in characters). Is there anyway to achieve this? Bonus question, is it possible to make hyperlinks via sharing via Gmail or SMS. For example, "Download here" where 'here' is a link instead of "Download by clicking the link below: http://..."
Current code:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, getTextToShare(data));
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, data.getTitle());
startActivity(Intent.createChooser(shareIntent, "Share this story"));
To find the selected share target this could be interesting for you: Branching the Android Share Intent extras depending on which method they choose to share
By using below code may helps you:
String shareText="Download <a href='[download link]'>here</a>";
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, Html.toHtml(shareText));
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, data.getTitle());
startActivity(Intent.createChooser(shareIntent, "Share this story"));
Share Url Links and Texts into Social Networks (Facebook,Twitter and linkedin)
I am now planning to share some text and link to SNS app in the phone.
And the code I use is below:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "the word i like to say");
shareIntent.setType("text/plain");
this.startActivity(Intent.createChooser(shareIntent, "share with below apps"));
return shareIntent;
there are so many options but unfortunately there is no Wechat Moments in it. Of course I can use shareSDK to achieve that, but the latter one has no Facebook/LinkedIn/Google+ in it. And there are too many 3rd libs included which I don't like. What is more, to show share options in two seperate menus is quite wired.
So, is there a way that I can add the option "Wechat moments" into the previous implementation(just like the image below) ? That will be quite helpful.
Wechat only accepts image.
Below will works.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(File obj));
shareIntent.setType("image/jpeg");
this.startActivity(Intent.createChooser(shareIntent, "share with below apps"));
return shareIntent;
I have developed an application. In this application, content is coming from database. The content I am getting in my textview , I just want to share the whole content using email etc..
How can I just send i.e share my available content.
I am getting all sharing options, but I am not able to share the content coming on screen.
Please let me know if you want more info!
Kindly Help me!
Thanks in Advance!
It's very simple. You just need to put in your intent.
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"yourEmail#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
emailIntent.putExtra(Intent.EXTRA_STREAM,yourTextView.getText());
emailIntent.setType("text/html");
startActivity(emailIntent);
Firstly, you should obtain the text that you want to share. Secondly, you can use an intent in order to show to the user the different ways to share the content. You can use this code to achieve it:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, textFromTextView);
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent,
"Share with..."));
I think AndroidWarrior's answer will only allow you to use e-mail but It's correct.
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));
I am working at sharing some info with an image from a resource. Here is the code I am using:
case R.id.menu_share:
//create the send intent
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
//set the type
shareIntent.setType("image/png");
//add a subject
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"CAR EXAMPLE");
//build the body of the message to be shared
String shareMessage = "An app...";
//add the message
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage);
//add the img
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://com.car.pack/drawable/" + Integer.toString(R.drawable.log)));
//start the chooser for sharing
startActivity(Intent.createChooser(shareIntent,"Share"));
break;
The problem is that in my example I am trying to share a TEXT+IMAGE from a resource. So, when I share with GMAIl app works perfect, but with the others app wich appears in the intent occurs:
Whatsapp : Only send the image, the text not.
SMS: not appears the text and the image.
email app from mobile (sony ericcson Arc S): break the app
Facebook: only share the image, the text no.
Bluetooth: I don´t test yet
So I think that the problem was on the text... or I don´t know, if anyone can help me...
THANKS!!!
Use shareIntent.setType("*/*"); .
Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.
Check here for more details.