I am currently trying to share text to gmail, facebook and twitter. I am using share intent method to share. Below is the code i used to share
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("plain/text");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My text");
startActivity(Intent.createChooser(sharingIntent,"Share using"));
The above code only show share options like gmail and skype. Why is facebook and twitter options not shown in the list even though i had the facebook and twitter application installed in my device?
Sharing with Facebook has the problem that it only accepts an url in the EXTRA_TEXT. The native FB app will then grab a text and an image from this url to compose the post. That's not a "bug" but the intended behaviour they give to the official app :-/
Take into account Twitter will only accept text/plain without any markup and with 144 chars at max.
I've made my own "Share" dialog to intercept all different behaviours and give to each target intent what they accepts: HTML, plain text, FB URL and Twitter short text.
Here comes the code:
Seems like some people wants the layout files too. Here are they:
dialog_share_us_chooser.xml
griditem_share_us.xml (from own AOSP project):
I don't know if anybody still reads this, but if people are still looking I found an easier answer:
And the getShareIntent method (this method searches through the mime type text/plain, you can use other mime types to search through those types or use /*/ to search through all types:
If you don't want to use this method you can just create Intents like this:
If you change the above line to:
sharingIntent.setType("text/plain");
, Would this problem be resolved?I think it's
text/plain
, notplain/text
.Reference from Android Developers: