0

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.

Amrutha
  • 575
  • 4
  • 9
  • 29

2 Answers2

1

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;
}
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
  • hi thank you...for facebook it is not showing the message on the wall...can we display default message on the facebook wall once it is opened? – Amrutha Nov 12 '13 at 12:11
  • Do you mean to say Facebook wall is not showing either of "Hello" and "I am sharing this"??? If yes please check your Facebook privacy setting (May be sharing mode is private). I didn't get you by saying "display default message on the Facebook wall once it is opened" – Rohit5k2 Nov 12 '13 at 12:17
  • yes I mean to say on Facebook wall is not showing either of "Hello" and "I am sharing this" – Amrutha Nov 12 '13 at 12:31
  • While sharing of FB a dialog opens. At the bottom left there is a option to select where you want to share the content. At the bottom right there is a option to select the privacy of the content. Make sure both are set correctly. After all this if you still can't see the shared content open the wall on web browser and see if that is available there. Also, you might wana check your FB privacy setting to publish things on your wall. I can't think of anything else which could be causing this issue. – Rohit5k2 Nov 12 '13 at 13:02
1

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));

AndyN
  • 1,742
  • 1
  • 15
  • 30