56

I have used Sharing-type intents before, such as:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "---" });
intent.putExtra(Intent.EXTRA_SUBJECT, "---");
startActivity(Intent.createChooser(intent, "Contact Us!"));

However, this basically shares with Email/MMS and other text or document type apps. How do you do this same things but include Social sharing like Facebook, Twitter and Google Plus (to name the important ones). And WHAT I want to share is the app, where the text says, "hey download this link to check out the app!" (or something similar along those lines).

TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259

7 Answers7

146

To add the Facebook, Twitter etc. share options, the user just needs to have those applications installed. It's up to other applications what type of Intents they will tell the system they can handle.

Then a basic ACTION_SEND intent will get picked up.

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
    "Hey check out my app at: https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
sendIntent.setType("text/plain");
startActivity(sendIntent);

Source

William Miller
  • 9,839
  • 3
  • 25
  • 46
ataulm
  • 15,195
  • 7
  • 50
  • 92
  • Perfect thanks. So it appears that simply by including Text in the intent (as opposed to the blank text body), it will add more social options? – TheLettuceMaster Dec 18 '12 at 20:52
  • no, it's the combination of "ACTION_SEND" and the fact that the user has applications which can handle "ACTION_SEND", as far as I know. Try blank text (i.e. don't "putExtra(..)") and let me know :D – ataulm Dec 18 '12 at 21:10
  • 1
    If you see my Question, in that example, I have `ACTION_SEND` with NO `EXTRA_TEXT` and only email clients, sms/mms clients, Google Drive, or Evernote on my phone come up. Although, I am specifying `EXTRA_EMAIL` so maybe that's why? – TheLettuceMaster Dec 19 '12 at 00:21
19

If you apply this code then it looks like the image below

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "My application name");
intent.putExtra(Intent.EXTRA_TEXT, "This is my text");
startActivity(Intent.createChooser(intent, "choose one"));

enter image description here

=====================================================================

If you apply this code then it looks like the image below

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
startActivity(sendIntent);

enter image description here

Prince Dholakiya
  • 3,255
  • 27
  • 43
7

You can do that by using a sharing intent

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey, download this app!");
            startActivity(shareIntent);     

you can put this intent in an onclick or use it whereever you want

I think this answers your question =)

3

In Kotlin we can do:

 private fun share(messageToShare: String, appUrl: String) {
    val intent = Intent(Intent.ACTION_SEND)
    intent.type = "text/plain"
    intent.putExtra(Intent.EXTRA_TEXT, messageToShare + appUrl)
    startActivity(Intent(intent))
}
Marcel Bro
  • 4,907
  • 4
  • 43
  • 70
Mahen
  • 760
  • 9
  • 12
2

Share the link to google play in the Intent.EXTRA_TEXT extra

iagreen
  • 31,470
  • 8
  • 76
  • 90
2

You can also add the title, subject, and body while sharing app:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My App Name");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_app_text));
                startActivity(Intent.createChooser(sharingIntent, "Share app via"));
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
1

try this its working fine for me :

 Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT,"I suggest this app for you : https://play.google.com/store/apps/details?id=com.android.chrome");
    intent.setType("text/plain");
    startActivity(intent);