33

As Facebook doesn't allow sharing text via Intent unless we use Facebook sdk, I am looking for a way around to achieve this.

I can think of 3 hacks which I can use:

1) As Facebook allows image sharing, I can generate a Bitmap with sharing text drawn onto it and share the image using Intent.

2) Facebook allows sharing URLs, for which it also displays the Head of the page while sharing. I can host a dedicated page on my server and pass values as parameter in the url, and generate the Head using it.(I have no experience with php, but I guess this is possible)

3) Copy text to clipboard and notify user about this.

OR

Use combinations of all 3.

Can anyone suggest me a much better way around to share my content on Facebook without using Facebook sdk?

Thanks in advance.

Hemanth
  • 2,717
  • 2
  • 21
  • 29
  • When I ran into this, my solution was to copy the text string to the clipboard, and notify the user via Toast, that they need to paste it. Crappy solution, but it works. – durbnpoisn Jan 05 '16 at 18:15
  • I am using this hack for one of my apps, but this time I am looking for much better way to share text. – Hemanth Jan 05 '16 at 18:17
  • You are not allowed to prefill the text for the user. You should read Facebook Platform Policy – WizKid Jan 05 '16 at 18:21
  • @WizKid : I totally understand that. That's the reason I am looking for a way around. For eg: I can share an image with sharing text on it, and it doesn't violate the policy. – Hemanth Jan 05 '16 at 18:25
  • There is no way to share texts without violate policy – WizKid Jan 05 '16 at 18:26
  • But in this case, I will be sharing an Image, not Text. – Hemanth Jan 05 '16 at 18:28
  • It really is a stupid policy. I have a bunch of apps that are little countdown timers. The Share button copies the remaining time and can be shared anywhere, with no troubles. Except FB. Oddly enough, you can send the URL for Google Play with no problems. Perhaps you can use that somehow. – durbnpoisn Jan 05 '16 at 18:53
  • Do you want to make the text appear in the Status Box of the Facebook? – Swaminathan V Jan 28 '16 at 12:26
  • @RaguSwaminathan : The Facebook Platform Policy won't allow me to do that. Instead, I would create a bitmap with text on it and share the bitmap. Any other much better hack which you can suggest? – Hemanth Jan 28 '16 at 14:15
  • did you try passing them as a link? – Swaminathan V Jan 28 '16 at 14:20
  • Passing text as a link? – Hemanth Jan 28 '16 at 14:21
  • You've given us good alternatives. Thank you. – Harsha Jan 09 '20 at 08:02

7 Answers7

61

There is no way you can share Text alone in the Facebook using android shareIntent.

It is possible only through Facebook SDK using share links functions.

Facebook simply ignores the Extra Text from the intent if there is an image. You can share image, but it does not allow you to share the Text content.

Unfortunately the Facebook sharing intent can only take a single URL with prefixed http:// and no additional text message. Actually facebook strips out the text content and allows only URL/Link. It is by Design and we have no control over it.

This will work

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
startActivity(Intent.createChooser(sharingIntent, "Share via"));

This will not work.

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Share Text from App");
startActivity(Intent.createChooser(sharingIntent, "Share via"));

Only approach you can share the text in the Facebook is using Facebook SDK.

Reference Links

Android share intent for facebook- share text AND link

Unable to share text with a link through Android Share Intent

Android and Facebook share intent

Community
  • 1
  • 1
Swaminathan V
  • 4,663
  • 2
  • 22
  • 32
  • 1
    Any way arounds to share my content on FB? like sharing an image with text drawn onto it. Or sharing a url and generate its head at run time. – Hemanth Feb 04 '16 at 11:18
  • do you want to share the image on FB? or Image separately, text separately on FB? Kindly clarify. – Swaminathan V Feb 04 '16 at 11:35
  • 1
    I just want to share bit of information on FB. I can think of sharing it via image **or** via a url **or** copying the text to clipboard and notify it to user so that user can paste it when FB app is opened. Any other tricks which I can use? – Hemanth Feb 04 '16 at 11:38
  • Why can't you try the Facebook SDK? which is simple enough for your need. – Swaminathan V Feb 04 '16 at 11:42
  • 2
    Just to share a single text, I won't go with implementing fb sdk in my app. And also, it's a managerial decision. – Hemanth Feb 04 '16 at 11:44
  • oh so sad. :( ok. so you want to share the image and text at the same time correct ? – Swaminathan V Feb 04 '16 at 11:47
  • Nope. I know that I can't share text on FB, but I can share a image. So I can create a bitmap with the text drawn onto it and share the image on fb. Any other way arounds? – Hemanth Feb 04 '16 at 11:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102592/discussion-between-ragu-swaminathan-and-hemanth). – Swaminathan V Feb 04 '16 at 11:59
  • @RaguSwaminathan is there any way to share a text too without using fb sdk ? – Karan Khurana Jun 15 '16 at 11:05
  • @KaranKhurana there is no way you can share the text without using the facebook sdk. Only you can share the url link without using the facebook SDK – Swaminathan V Jun 16 '16 at 05:29
  • As I know, according to facebook's policy, application can't pre-fill text while sharing. Only user can fill text on THEIR walls. – RRTW Jul 05 '17 at 01:49
  • @Karan Khurana, right now it seems there is no way even to share the text USING facebook sdk. it only lets you share link, photo, video and one hashtag. where you ever able to share text using fb sdk? – Dhunju_likes_to_Learn Apr 25 '18 at 20:18
5

First of all, in order to share text on FB, you got to use FB SDK.

Without FB SDK better option is to go for a dedicated website with "OG" data, which will get resolved automatically. By this, you can change your OG data when ever you need a change.

I would suggest you to go for your hack number 2. But, with this approach, FB allows users to click on the link and redirects to the website, you may try to handle this according to your requirement.

I hope you are clarified with this.

For details on OG please check this Open Graph details

Karthik Kumar
  • 1,375
  • 1
  • 12
  • 29
4

Use this function, I hope it will help

public static void share(Context context, String text, String subject, String title, String dialogHeaderText) {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    intent.putExtra(Intent.EXTRA_TITLE, title);
    context.startActivity(Intent.createChooser(intent, dialogHeaderText));
}
Hassan Jamil
  • 951
  • 1
  • 13
  • 33
4

This code lets you paste your content on only on facebook. what id do is get the list of all apps present in your phone and find the open then open facebook app if is already present

        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text to be shared");
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
        for (final ResolveInfo app : activityList) {
            if ((app.activityInfo.name).contains("facebook")) {
                final ActivityInfo activity = app.activityInfo;
                final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                shareIntent.setComponent(name);
                startActivity(shareIntent);
                break;
           }
        }
  • If I follow the code correctly, it will open FB app with no sharing text in it. User is responsible to type or paste the text. right? – Hemanth Feb 04 '16 at 11:35
  • shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text to be shared"); what this line does is you have your own copied text with you. – Harsh Dev Chandel Feb 04 '16 at 11:58
  • 4
    The `EXTRA_TEXT` `text to be shared` will not be shown when fb app openes. – Hemanth Feb 04 '16 at 11:59
  • Opening the facebook app is not ideal. Your code is on the right track. Once the if condition is met, instead of opening the facebook app, use facebook sdk to open its own share dialog so you can include text and image at the same time. – chitgoks Apr 19 '17 at 08:16
3

Check this :

Intent share=new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "Some text you would like to share...");
share.setPackage("com.facebook.katana"); //Facebook App package
startActivity(Intent.createChooser(share, "Title of the dialog the system will open"));

You don't need facebook SDK with this code......

To enhance your UX, you can do a check if Facebook App(or FacebookLite App) ware installed...

RRTW
  • 3,160
  • 1
  • 35
  • 54
1

When you use native intent it's up to the app the user shares with if it uses the data from the intent or not.

This is a known bug and facebook have made this bug to wishlist. Maybe they are not trying to fix it. This is intentional to make people use FB SDK i think. refer this link http://forum.developers.facebook.net/viewtopic.php?id=93900 and this post

http://forum.developers.facebook.net/viewtopic.php?id=93900

Community
  • 1
  • 1
bpr10
  • 1,086
  • 8
  • 14
  • (this doesn't answer the question) I totally understand that. That's the reason I am looking for a way around. For eg: I can share an image with sharing text on it, and it doesn't violate the policy. Any better suggestions? – Hemanth Jan 29 '16 at 12:01
  • I probably didn/t get your question then. Using text on an Image or copying the text to the clipboard and showing toast to paste can be possible workarounds. Shit. Downvoted :( – bpr10 Jan 29 '16 at 12:17
-1

If you don't mind other sharing options being presented you can just use a regular sharing intent with a picker since Facebook will be one of the options to share if they have it enabled.

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, "Choose sharing method"));
chosendeath
  • 106
  • 1
  • 7