0

i want to share some text and variable values on facebook. i try some code but it opens facebook for sharing on timeline but didnot include text in that so how to fix it,

ShareLinkContent linkContent=new ShareLinkContent.Builder()
                                        .setQuote("Today my Activity is\n Steps taken by me = "+currentSteps
                                        +"\n  Calories burn by me =" + calories+
                                        "\n Distance that i covered = "+ distanceCover).build();
                                shareDialog.show(linkContent);

i am trying this code in alertDialogBox's button. i am using android studio 3.1.4 with API 28.

Learn Do
  • 41
  • 1
  • 5

2 Answers2

0

Sadly, there is no way to share "any" text so easily on Facebook you can share urls with the regular text share intent... like this:

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

But that will work just with urls. If you want to share any content (text) you'll have to use the Facebook SDK

https://developers.facebook.com/docs/sharing/android

Good luck!

amilcar-sr
  • 1,050
  • 9
  • 21
  • but i also have facebook app id and hashkey , and integrate that app with facebook login , is it work? – Learn Do Nov 05 '18 at 20:36
  • That's a start, but that's just for authentication purposes :) in order to share the content you want, you'll have to follow the steps in the documentation I shared above (https://developers.facebook.com/docs/sharing/android) – amilcar-sr Nov 05 '18 at 21:25
  • i already follow that steps but i dont get result. if you know how to do it so please help me with code – Learn Do Nov 06 '18 at 05:07
0

I have achieved a workround by using the clipboard as an intermediary, the user has full control; my app doesn't paste the text but the user can. See this https://stackoverflow.com/a/53323770/8424520

Ned
  • 61
  • 1
  • 2