Amrutha
Amrutha

Reputation: 575

How to share text in twitter,facebook and email in android?

I am working on android application. My app contains a listview and when each listitem is clicked I am displaying its related content in new activity. Now I kept a share button in the new activity and when that button is clicked I am displaying an alert with fb,twitter and email icon. Now when I click on twitter the text in that page should be posted in twitter. Similarly for facebook and email. Please suggest me how to share text via social networking in android. I didnt work on sharing via social network android. Any suggestion or links may be helpful.

I have gone through examples in google but I didnt understood the flow.

Upvotes: 0

Views: 883

Answers (2)

AndyN
AndyN

Reputation: 1754

String message = "Text you want to share."; Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, message); startActivity(Intent.createChooser(shareIntent, your title here));

Upvotes: 1

Rohit5k2
Rohit5k2

Reputation: 18112

use this and let user choose where he/she wants to share it

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Hello");
i.putExtra(Intent.EXTRA_TEXT, "I am sharing this");
try 
{
    this.startActivity(Intent.createChooser(i, "Share..."));
} 
catch (android.content.ActivityNotFoundException ex) 
{
    //Error
    return;
}

Upvotes: 1

Related Questions