How To Share An Image On Facebook In Android

how to share on facebook

how to share on facebook
How to share on facebook

Let’s learn how to share an image on Facebook in Android using their ever-changing API. If you have used Facebook’s Android SDK, you know it can be a PITA to say the least. I think Mark should give the developers a vacation for heck’s sake!

How To Share An Image On Facebook In Android – Sample Code

Before you can use Facebook’s Android SDK in your Android application (to add features like sharing, liking etc), you have several options of including their SDK in your project. For instance:

1) Download the entire SDK from Github or Facebook and include it as a Module in your Android studio.
2) Using Gradle – this by far is the easiest way to use Facebook’s Android SDK – among other third-party libraries. I am going to show you how to do this next.

So, the first thing to do is to open your Android Project and open build.gradle (Module: app) file and under dependencies clause, add the following:

I am assuming (with caution) that you have created an App – if not, go to developers.facebook.com. Once you do so, you will be given an App Id that you will need to use. Save it in your strings.xml file. In your AndroidManifest.xml file, do this:

SharingActivity.java

We can finally add our sample code to see how to share an image on Facebook wall!

This is what you should see if you copied my sample code as-is:

how to share on facebook

Once you run this code – of course you have to use an existing drawable in the sharePhotoToFacebook method for this to work and have an internet connection.

That is a wrap on how to share an image on Facebook in Android code; remember this sample code does not use regular LoginButton from Facebook. You can easily add that if you would like that kind of thing!

You can read more about Facebook Sharing by visiting their docs.

Please, if you have questions, let me know through comments below. Also, consider sharing this post if you found it helpful!

Written By Elisha Chirchir

Elisha Chirchir is a software developer. He is also the founder of Simple Developer and co-founder of Instinctive Software Solutions. On any given day, he works on both Android and Web Development. During his ‘free time’, he offers training to those interested in learning how to code in php, java, python, javaScript etc. You can easily find him on StackOverflow Android chatroom or on Twitter @Eenvincible

59 Comments on “How To Share An Image On Facebook In Android

  1. selin Reply

    June 10, 2015 at 2:30

    Hi,

    I’m trying this code. I can share photo but the caption doesn’t display. Please, help me.

    Thank you so much

    • Elisha Chirchir Reply

      June 18, 2015 at 9:10

      First of all, to save you massive pain later on during Facebook Review process, if there is any automatic caption being added to the post, Facebook does NOT allow that. Unless you let users compose the caption.

      To add a caption, you simple add like I did in the sample code. Please show me how you are adding your caption.

      • kushi Reply

        November 6, 2015 at 7:21

        Hi thanks for ur code, but will crashes when activity starts..it is is showing Runtime exception plz help me
        java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity {com.example.kumaraswamy.sharingactivity/com.example.kumaraswamy.sharingactivity.ShareActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:3626)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3669)
        at android.app.ActivityThread.access$1300(ActivityThread.java:148)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5312)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
        Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference
        at com.facebook.login.LoginManager.getLogger(LoginManager.java:392)
        at com.facebook.login.LoginManager.logCompleteLogin(LoginManager.java:415)
        at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:190)
        at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:140)
        at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:82)
        at com.example.kumaraswamy.sharingactivity.ShareActivity.onActivityResult(ShareActivity.java:85)
        at android.app.Activity.dispatchActivityResult(Activity.java:6161)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:3622)
                    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3669)
                    at android.app.ActivityThread.access$1300(ActivityThread.java:148)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:135)
                    at android.app.ActivityThread.main(ActivityThread.java:5312)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:372)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

    • sairam Reply

      September 21, 2016 at 4:49

      this sharing only working through developers account only.
      what i have to do to any user can share his image from our application?

      • Elisha Chirchir Reply

        November 11, 2016 at 8:13

        Read Facebook developer instructions on how to make your app public!

    • vicky Reply

      April 27, 2017 at 9:34

      image share from fb but caption not support so how solve it

  2. Jeremy Reply

    June 17, 2015 at 2:17

    Hi, Elisha, can you help me? I created a button listener to start the SharingActivity, I followed your code. But I got the errors,
    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String java.lang.Throwable.toString()’ on a null object reference on the line Log.v(“LoginActivity”, exception.getCause().toString());

    and once I commented out these line, the facebook sharing screen only stayed on the screen for less than one second. What is in your activity_main.xml by the way?

    • Elisha Chirchir Reply

      June 18, 2015 at 9:07

      Sorry about the errors Jeremy. First, I assume – with caution here, that you have the Internet Permission in your AndroidManifest file. Secondly, Since I do not use a Login Button in my xml file (I use a LoginManager instance instead), when someone clicks a button you perhaps added to the view to login, I just run the code inside onCreate where I loginWithRead/Publish permission depending on what you want the permissions for. I would like to see your code if you don’t mind so I can help you farther. Let me know how it goes.

  3. Selvam Reply

    June 24, 2015 at 3:18

    What have you done in your activity_main.xml?

    • Elisha Chirchir Reply

      June 24, 2015 at 7:29

      There is nothing in that layout file. The reason is because I do not use Facebook LoginButton button; I use LoginManager class – which is an alternative to using the LoginButton provided by the Facebook Android SDK. So, as soon as you go to this activity, the login dialog pops up!

  4. maha Reply

    July 8, 2015 at 12:46

    Hi i have tried above code its working well,but the problem is images are posting from one specific login FB id only when i try with different login FB id images are not posting,can you tel me what is the problem

    • Elisha Chirchir Reply

      July 8, 2015 at 12:58

      I suspect it is because you have not submitted your app for review by Facebook Team! You have to do this before you release the app to the public so that users can actually post the app using a different account other than your developer account – which currently works for you!

      • MAHA Reply

        July 9, 2015 at 6:42

        Thank you Elisha

  5. Glenn Reply

    August 16, 2015 at 8:51

    I followed your code to the letter but I get a java.lang.RuntimeException:

    08-16 22:45:50.781: E/AndroidRuntime(25098): FATAL EXCEPTION: main
    08-16 22:45:50.781: E/AndroidRuntime(25098): Process: be.thomasmore.powerfactory, PID: 25098
    08-16 22:45:50.781: E/AndroidRuntime(25098): java.lang.RuntimeException: Unable to start activity ComponentInfo{be.thomasmore.powerfactory/be.thomasmore.powerfactory.FacebookActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

    • Elisha Chirchir Reply

      August 24, 2015 at 8:43

      The error says you need to use AppCompat theme – so I suspect you have not used it in your styles.xml or themes.xml file.

  6. jatin Reply

    August 20, 2015 at 7:19

    i successfully share image but i can’t share caption ELISHA CHIRCHIR

    • Elisha Chirchir Reply

      August 24, 2015 at 8:42

      Did you set the caption like I did in my code? May I see your code example? Copy and paste it to pastebin then share a link with me?

  7. MA Reply

    August 21, 2015 at 4:00

    Hello, could I ask please about returning back??

    I tried this code, I have a fragment class which has a button that lunch the Facebook Activity class (which has the code above). after pressing the button, blank page appears and still forever in spite of the image is posted to Facebook. I want by pressing this button, to launch the facebook actitvity in background to stay in the same view and then show Toast message that says everything is OK. I tried multiple ways but I did not succeed. I think the callback manager does not work with me. Any help please??

    • Elisha Chirchir Reply

      August 24, 2015 at 8:41

      I just wanted to suggest you do a toast inside onSuccess method of your callback. I would have to see your code to help further!

  8. sarah Reply

    August 27, 2015 at 12:11

    Hello,
    I’m trying this code. I can share photo but the caption can’t work.
    Here is my code.
    [SharePhoto photo = new SharePhoto.Builder().setBitmap(bitmap)
    .setCaption(“Hey this is Demo post!”)
    .build();
    ArrayList photos = new ArrayList();
    photos.add(photo);

    SharePhotoContent.Builder shareContentBuilder = new SharePhotoContent.Builder();
    shareContentBuilder.addPhotos(photos);
    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(
    photo).build();]
    Can you have a look?Thank you so much

    • Elisha Chirchir Reply

      August 27, 2015 at 1:48

      In my code sample, I show how to add caption to the image; I cannot clearly see that you are not doing that here in your code. Take a look at my code again please!

      • Sarah Reply

        November 26, 2015 at 2:42

        Thank you so much,I try your code,it’s work now.But is there possible showing ShareDialog ,not just post on wall?I try this way, it can show photo but cannot with text.

        if (ShareDialog.canShow(SharePhotoContent.class)) {
        SharePhoto photo = new SharePhoto.Builder()
        .setCaption(“test”)
        .setBitmap(bitmap)
        .build();
        SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .build();
        shareDialog.show(content);
        }

  9. Aman Dhindsa Reply

    October 7, 2015 at 6:37

    hi @Elisha Chirchir
    thanks for example but this code does not work on my side… please help me..

    • Elisha Chirchir Reply

      October 7, 2015 at 8:27

      Would you please give me more details on the error message you are getting?
      I can help you more if I have the details of what is happening. Thanks

      • Aman Dhindsa Reply

        October 9, 2015 at 5:07

        public class myfbshare extends Activity {
        private CallbackManager callbackManager;
        private LoginManager loginManager;
        Bitmap bm;
        String pic,sms,toclass;
        ShareDialog shareDialog;
        @Override
        protected void onActivityResult(int requestCode, int responseCode, Intent data)
        {
        super.onActivityResult(requestCode, responseCode, data);
        callbackManager.onActivityResult(requestCode, responseCode, data);
        }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(this.getApplicationContext());
        setContentView(R.layout.myfbshare);

        callbackManager = CallbackManager.Factory.create();
        shareDialog = new ShareDialog(this);
        List permissionNeeds = Arrays.asList(“publish_actions”);

        //this loginManager helps you eliminate adding a LoginButton to your UI
        loginManager = LoginManager.getInstance();

        loginManager.logInWithPublishPermissions(this, permissionNeeds);
        pic=getIntent().getStringExtra(“pic”);
        sms=getIntent().getStringExtra(“sms”);
        toclass=getIntent().getStringExtra(“class”);

        if(toclass.contains(“pic”))
        {
        System.out.println(“smsclass==”+”pic”);

        loginManager.registerCallback(callbackManager, new FacebookCallback()
        {
        @Override
        public void onSuccess(LoginResult loginResult)
        {
        sharePhotoToFacebook();
        System.out.println(“smsclass==”+”yes it done”);
        }

        @Override
        public void onCancel()
        {
        System.out.println(“smsclass==”+”onCancel”);
        finish();
        }

        @Override
        public void onError(FacebookException exception)
        {
        exception.printStackTrace();
        System.out.println(“smsclass==”+”onError”);
        finish();
        }
        });

        }
        else
        {
        System.out.println(“smsclass==”+”sms”);

        if (ShareDialog.canShow(ShareLinkContent.class)) {
        ShareLinkContent linkContent = new ShareLinkContent.Builder()

        .setContentTitle(“SantaBanta.com”)
        .setContentDescription(sms)
        .setContentUrl(Uri.parse(“http://www.santabanta.com/sms/”))
        .build();

        shareDialog.show(linkContent);

        finish();

        }
        }
        }

        private void sharePhotoToFacebook( ){

        new myclass().execute();

        }

        public class myclass extends AsyncTask
        {

        @Override
        protected String doInBackground(String… arg0) {
        try {
        System.out.println(“smsclass==”+pic);

        URL url = new URL(pic);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        bm=myBitmap;
        System.out.println(“smsclass==”+ bm);

        } catch (IOException e) {
        e.printStackTrace();
        }

        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

        //Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(bm)
        .setCaption(“SantaBanta.com”)
        .build();
        System.out.println(“smsclass==”+”yes it done 2nd time”);
        SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .build();
        System.out.println(“smsclass==”+”finally it done”);

        ShareApi.share(content, null);

        finish();
        return null;
        }

        }

        this my class and my loginManager.registerCallback(callbackManager, new FacebookCallback()

        goes to public void onError(FacebookException exception)
        {
        exception.printStackTrace();
        System.out.println(“smsclass==”+”onError”);
        finish();
        }
        and it does not show any error…

        • Aman Dhindsa Reply

          October 9, 2015 at 5:09

          public class myfbshare extends Activity {
          private CallbackManager callbackManager;
          private LoginManager loginManager;
          Bitmap bm;
          String pic,sms,toclass;
          ShareDialog shareDialog;
          @Override
          protected void onActivityResult(int requestCode, int responseCode, Intent data)
          {
          super.onActivityResult(requestCode, responseCode, data);
          callbackManager.onActivityResult(requestCode, responseCode, data);
          }
          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          FacebookSdk.sdkInitialize(this.getApplicationContext());
          setContentView(R.layout.myfbshare);

          callbackManager = CallbackManager.Factory.create();
          shareDialog = new ShareDialog(this);
          List permissionNeeds = Arrays.asList(“publish_actions”);

          //this loginManager helps you eliminate adding a LoginButton to your UI
          loginManager = LoginManager.getInstance();

          loginManager.logInWithPublishPermissions(this, permissionNeeds);
          pic=getIntent().getStringExtra(“pic”);
          sms=getIntent().getStringExtra(“sms”);
          toclass=getIntent().getStringExtra(“class”);

          if(toclass.contains(“pic”))
          {
          System.out.println(“smsclass==”+”pic”);

          loginManager.registerCallback(callbackManager, new FacebookCallback()
          {
          @Override
          public void onSuccess(LoginResult loginResult)
          {
          sharePhotoToFacebook();
          System.out.println(“smsclass==”+”yes it done”);
          }

          @Override
          public void onCancel()
          {
          System.out.println(“smsclass==”+”onCancel”);
          finish();
          }

          @Override
          public void onError(FacebookException exception)
          {
          exception.printStackTrace();
          System.out.println(“smsclass==”+”onError”);
          finish();
          }
          });

          }
          else
          {
          System.out.println(“smsclass==”+”sms”);

          if (ShareDialog.canShow(ShareLinkContent.class)) {
          ShareLinkContent linkContent = new ShareLinkContent.Builder()

          .setContentTitle(“SantaBanta.com”)
          .setContentDescription(sms)
          .setContentUrl(Uri.parse(“http://www.santabanta.com/sms/”))
          .build();

          shareDialog.show(linkContent);

          finish();

          }
          }
          }

          private void sharePhotoToFacebook( ){

          new myclass().execute();

          }

          public class myclass extends AsyncTask
          {

          @Override
          protected String doInBackground(String… arg0) {
          try {
          System.out.println(“smsclass==”+pic);

          URL url = new URL(pic);
          HttpURLConnection connection = (HttpURLConnection) url.openConnection();
          connection.setDoInput(true);
          connection.connect();
          InputStream input = connection.getInputStream();
          Bitmap myBitmap = BitmapFactory.decodeStream(input);
          bm=myBitmap;
          System.out.println(“smsclass==”+ bm);

          } catch (IOException e) {
          e.printStackTrace();
          }

          ByteArrayOutputStream bytes = new ByteArrayOutputStream();
          bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

          //Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
          SharePhoto photo = new SharePhoto.Builder()
          .setBitmap(bm)
          .setCaption(“SantaBanta.com”)
          .build();
          System.out.println(“smsclass==”+”yes it done 2nd time”);
          SharePhotoContent content = new SharePhotoContent.Builder()
          .addPhoto(photo)
          .build();
          System.out.println(“smsclass==”+”finally it done”);

          ShareApi.share(content, null);

          finish();
          return null;
          }

          }

          this my class and my loginManager.registerCallback(callbackManager, new FacebookCallback()

          goes to public void onError(FacebookException exception)
          {
          exception.printStackTrace();
          System.out.println(“smsclass==”+”onError”);
          finish();
          }
          and it does not show any error…
          thanks….

          • Elisha Chirchir

            October 9, 2015 at 5:29

            Please give me a moment to try out your code then respond accordingly.

      • Aman Dhindsa Reply

        October 9, 2015 at 5:38

        i can share image using this code from my emulator. but i could not share image with android device..

  10. quocviet Reply

    October 7, 2015 at 8:11

    I tried but it did happen this error:The publish_actions permissions are missing, the share will fail unless this app was authorized to publish in another installation. please help me!!

    • Elisha Chirchir Reply

      October 7, 2015 at 8:25

      First, make sure you are using the right appID from your developer account on Facebook. Then make sure you are using the same development environment – if you have another developer working on this project and they submitted a different hash key than yours, then you might have inconsistencies – meaning you should have them add their hash key to the app settings page on Facebook.

      Let me know how it goes;

  11. Tiago Reply

    October 8, 2015 at 2:40

    Hi, it was really helpful. Im trying to share an image from my app after I apply some filters on it, but when I share my image do not display for my friends, just the caption is visible.
    Do you know why it is happening?
    Thanks

    • Elisha Chirchir Reply

      October 8, 2015 at 4:26

      I am not entirely sure what is causing this for your code. I would like to see all the permissions you are requesting from Facebook. is there a way you could share your code and I can take a look at it?

  12. […] I’m trying to learn how to share a simple image using android and facebook SDK following this tutorial. […]

  13. Gil Garibi Reply

    November 1, 2015 at 3:32

    Hi Elisha,

    I am doing the exactly same thing except using setImageUrl on the SharePhoto.Builder (instead of setBitmap). The image is posted successfully but the caption doesn’t show. When I switch to setBitmap, the caption does show. Does this make sense to you?

    Thanks,
    Gili

    • Elisha Chirchir Reply

      November 1, 2015 at 5:31

      I unfortunately don’t understand why! The last time I tested this code, it posted both – but Facebook keeps updating their SDK like on a daily basis for hell’s sake!

  14. edo Reply

    November 7, 2015 at 2:46

    Hi,

    Nice to meet your website here 🙂 lucky me 🙂

    0
    down vote
    favorite

    I just tried to follow the official guidance from Facebook of how to integrate my application to Facebook Messenger.

    Somewhere there is a Java statement with empty argument. Just dots “…”. Or, do I have to put the dots as is ?

    Bitmap image = …
    SharePhoto photo = new SharePhoto.Builder()
    .setBitmap(image)
    .build();
    SharePhotoContent content = new SharePhotoContent.Builder()
    .addPhoto(photo)
    .build();

    or this:

    Uri videoFileUri = …
    ShareVideo = new ShareVideo.Builder()
    .setLocalUrl(videoUrl)
    .build();
    ShareVideoContent content = new ShareVideoContent.Builder()
    .setVideo(video)
    .build();

    Please help because I dont know Java ..

    Thank you 🙂

  15. Ankit Kamboj Reply

    February 10, 2016 at 5:04

    Hi Elisha, I want to share multiple images on Facebook at a time. How can i achieve it? Please help me.

    • Elisha Chirchir Reply

      February 10, 2016 at 8:29

      Have you tried a loop? Do you know how many images you have to share? Because if you do, you can or might have to create that number of asyncronous calls

  16. birdun2013 Reply

    February 11, 2016 at 6:22

    Hi great tutorial but will this work if we are using eclipse instead of android studio I think in eclipse we don’t have gradle thanks!

  17. Law Reply

    March 15, 2016 at 3:35

    Hi, I was able to share image but can I know how do I get the URL after I share image on Facebook?
    Here’s my code. Really appreciate if can help me on this.

    SharePhoto photo = new SharePhoto.Builder().setBitmap(image).setCaption(“PHOTO CAPTION”).build();

    SharePhotoContent PhotoContent = new SharePhotoContent.Builder().addPhoto(photo).build();
    shareDialog.show(PhotoContent, ShareDialog.Mode.AUTOMATIC);

    shareDialog.registerCallback(CallbackMng, new FacebookCallback() {
    @Override
    public void onSuccess(Sharer.Result result) {
    // result.getPostId()
    // POST ID ALWAYS NULL
    }

    @Override
    public void onCancel() {
    // CANCEL
    }

    @Override
    public void onError(FacebookException error) {
    // ERROR
    }

    });

  18. Pradeep Bishnoi Reply

    March 16, 2016 at 7:39

    Hii
    Great Thanks Dear very helpfull
    Best of luck for further post

    Pradeep Bishnoi

  19. Doğanay Reply

    July 4, 2016 at 8:15

    Hİ Elisha thanks for tutorial is the best I ‘ ve ever seen about this topic.

  20. Ali AKRAM Reply

    August 25, 2016 at 11:01

    Hey !! This code worked for me but whatever the image i post through this can only be see by only myself !!Even my facebook privacy is set as friends but still it not visible to others ..WHY ??

    • Elisha Chirchir Reply

      September 4, 2016 at 3:56

      That is weird behavior unless the Facebook Graph API has changed!

    • Yoonnyung Choi Reply

      September 29, 2016 at 2:44

      I have the exact same problem too!!

  21. jatin bansal Reply

    August 26, 2016 at 7:03

    hlo sir,when i am using your code in onClickListener then it jst initalize the facebook after that return my MainActivity.this not share image on Facebook.

    facebook.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    // shareDialog=new ShareDialog(MainActivity.this);

    List permissionNeeds = Arrays.asList(“publish_actions”);
    manager = LoginManager.getInstance();

    manager.logInWithPublishPermissions(MainActivity.this, permissionNeeds);

    manager.registerCallback(callbackManager, new FacebookCallback() {
    @Override
    public void onSuccess(LoginResult loginResult) {
    publishImage();
    }

    @Override
    public void onCancel() {
    System.out.println(“onCancel”);

    }

    @Override
    public void onError(FacebookException error) {
    System.out.println(“onError”);

    }
    });

    private void publishImage(){
    Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.fb);

    SharePhoto photo = new SharePhoto.Builder()
    .setBitmap(image)
    .setCaption(“Welcome To Facebook Photo Sharing on steroids!”)
    .build();

    SharePhotoContent content = new SharePhotoContent.Builder()
    .addPhoto(photo)
    .build();

    ShareApi.share(content, null);

    }

    @Override
    protected void onActivityResult(final int requestCode, final int resultCode,final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode,resultCode,data);
    }

    }

  22. Zeeshan Shahid Reply

    November 30, 2016 at 12:57

    what modifications I have to do in this code if want to share a link or status on facebook??

  23. Hardik miyani Reply

    December 21, 2016 at 12:26

    Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

    R.mipmap.ic_launcher here i put my path for get image from storage
    but how to do this

  24. Razia Reply

    January 10, 2017 at 5:31

    Hii Elisha

    Is it possible to multiple images on facebook??

  25. Razia Reply

    January 10, 2017 at 5:31

    Hii Elisha

    Is it possible to share multiple images on facebook??

    • Elisha Chirchir Reply

      January 26, 2017 at 8:10

      I am not absolutely sure on this; but I will get back to you when I find out!

  26. chandra boyilla Reply

    March 15, 2017 at 2:27

    this code is working like charm, but one issue – all images which ever shred by me at different intervals of time are going to single album, i don’t want this to happen, i need like upload and show individual posts . any solution please…..

  27. kinjal Reply

    May 8, 2017 at 11:29

    it ads in album instead of adding in upload post

  28. Pál Matolay Reply

    May 20, 2017 at 1:02

    Really thanks for that!
    Finally, I successfully done with this. So, I can continue my own work.
    Thanks a lot!
    (I upload my result on github and, of course I let a link about this tutorial in the readme)

    • Elisha Chirchir Reply

      May 24, 2017 at 9:39

      You can share your repository here in the comments for others to use!

Leave a Reply

Your email address will not be published. Required fields are marked *