skip to Main Content

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 isn 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.

2

Answers


  1. 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! 😄

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search