-1

I'm new to andoird development, have a bit of java knowledge and I am currently stuggling to implement a facebook share option in my andorid app.

I have code of an android app and I want to add an option upon clicking, the user shares my app to facebook.

I have imported the Facebook SDK etc and added everything needed to the manifest, however I'm now struggling to get the share to facebook working, I want to use the 'ShareLinkContent' option.

I have tried to follow the facebook developers page and many pages on here such as:-

Integrating Facebook Sharing into my app

However as I purchased the app source code, I haven't done much in terms of android coding.

I've tried adding this bit of code to the 'case' in my code:-

ShareLinkContent content = new ShareLinkContent.Builder()
    .setContentTitle("This is the title")
    .setContentDescription("This is the description")
    .setContentUrl(Uri.parse("www.google.com"))
    .build();

However, when clicking the button nothing shows up? Any help would be much appreciated.

Thanks

Community
  • 1
  • 1

3 Answers3

0

Try this code

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
sharingIntent.setType("text/plain");
String shareBody = "Here is the share content body";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
Ishvar Kikani
  • 1,394
  • 2
  • 8
  • 13
  • 1
    Thanks, I did get this working, HOWEVER, from this I wanted it to just show the share to Facebook option directly. Not giving the user the option to choose how to share it, if you understand me? – Gift Me Uk Apr 29 '17 at 12:47
  • @GiftMeUk take a look at [this](http://stackoverflow.com/a/8312422/3134215) – Ravi Apr 29 '17 at 12:57
0

If you want to share text on Facebook without any using Facebook share dialog , Then you need "publish_action" permissions Approved On Facebook dashboard app

Please go through the link and read the article https://developers.facebook.com/docs/sharing/android

Sukhbir
  • 1,410
  • 14
  • 33
-1

I created this function for sharing.. check this.. It may be help you

public void sendPostDialog(String msg, Uri image_uri) {
    try {
        ShareDialog shareDialog = new ShareDialog(activity);
        shareDialog.registerCallback(mCallbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {
                Toast.makeText(context, "Send post Completed", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onCancel() {
                Toast.makeText(context, "Send post Canceled", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(FacebookException error) {

                Toast.makeText(context, error.getMessage(), Toast.LENGTH_LONG).show();
            }
        });

        if (ShareDialog.canShow(ShareLinkContent.class)) {
            ShareLinkContent linkContent = new ShareLinkContent.Builder()
                    .setContentTitle("Share Location on FB")
                    .setContentDescription(msg)
                    .setContentUrl(image_uri))
                    .build();
            shareDialog.setShouldFailOnDataError(false);
            shareDialog.show(linkContent, ShareDialog.Mode.FEED);
        } else {
            Log.print("MyFacebook post nested else");
        }
    } catch (Exception e) {
        Log.print("MyFacebook post", e.getMessage());
        e.printStackTrace();
    }
}
Upendra Shah
  • 2,218
  • 17
  • 27
  • Thank you, however as I'm new to android development, when I add this function to my code within 'case' I'm getting a lot of red lines lol. For example 'msg' 'image_uri' etc. In java I would add String msg; before my 'method' however I'm not sure why these are underlined in red within android studio. – Gift Me Uk Apr 29 '17 at 19:27
  • you have to just copy this function in a class where you initialized your facebook sdk then call this function from 'case' with passing two parameters (String msg, Uri image_uri) in msg you can set your message and in image_uri you can pass uri of image which you want to share.. – Upendra Shah Apr 30 '17 at 05:58
  • Thank you so much, so if I wanted to pass through the link to my app along with some text, I simply pass that through as msg then my logo for example through as the img_uri. Do you know why I'm getting these messages for certain parts of your function? http://imgur.com/b23e2d54-76e4-4b2d-9dc1-8e9c36673137 I'm sure I've imported the facebook sdk correctly? – Gift Me Uk Apr 30 '17 at 09:14
  • mCallbackmanager is mange the facebook callback so i think you haven't implements CallBackManger to your class.. and context is your activity's context or you can say activity.. – Upendra Shah Apr 30 '17 at 13:25