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:
1 2 3 4 5 6 7 |
dependencies{ compile 'com.facebook.android:facebook-android-sdk:4.1.0' } |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<uses -permission android:name="android.permission.INTERNET">< \/uses-permission> <application android:label="@string/app_name" ...> ... <meta -data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> //to use login or share add this <activity android:name="com.facebook.FacebookActivity" android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name"> </activity> //replace 1234 below with your Facebook App Id <provider android:authorities="com.facebook.app.FacebookContentProvider1234" android:name="com.facebook.FacebookContentProvider" android:exported="true"> </provider> ... </application> |
SharingActivity.java
We can finally add our sample code to see how to share an image on Facebook wall!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
public class SharingActivity extends AppCompatActivity{ private CallbackManager callbackManager; private LoginManager loginManager; @Override protected void onCreate(Bundle savedInstanceState){ { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); List<string> permissionNeeds = Arrays.asList("publish_actions"); //this loginManager helps you eliminate adding a LoginButton to your UI manager = LoginManager.getInstance(); manager.logInWithPublishPermissions(this, permissionNeeds); manager.registerCallback(callbackManager, new FacebookCallback< \LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { sharePhotoToFacebook(); } @Override public void onCancel() { System.out.println("onCancel"); } @Override public void onError(FacebookException exception) { System.out.println("onError"); } }); } private void sharePhotoToFacebook(){ Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); SharePhoto photo = new SharePhoto.Builder() .setBitmap(image) .setCaption("Give me my codez or I will ... you know, do that thing you don't like!") .build(); SharePhotoContent content = new SharePhotoContent.Builder() .addPhoto(photo) .build(); ShareApi.share(content, null); } @Override protected void onActivityResult(int requestCode, int responseCode, Intent data) { super.onActivityResult(requestCode, responseCode, data); callbackManager.onActivityResult(requestCode, responseCode, data); } } |
This is what you should see if you copied my sample code as-is:
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!
selin
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
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
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)
Elisha Chirchir
Can you share the code line that causes this?
sairam
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
Read Facebook developer instructions on how to make your app public!
vicky
image share from fb but caption not support so how solve it
Jeremy
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
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.
Selvam
What have you done in your activity_main.xml?
Elisha Chirchir
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!
maha
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
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
Thank you Elisha
Glenn
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
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.
jatin
i successfully share image but i can’t share caption ELISHA CHIRCHIR
Elisha Chirchir
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?
MA
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
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!
sarah
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
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
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);
}
What's the caption character limit on facebook? - BlogoSfera
[…] and this: http://simpledeveloper.com/how-to-share-an-image-on-facebook-in-android/ […]
What’s the caption character limit on facebook? | Solutions for enthusiast and professional programmers
[…] and this: http://simpledeveloper.com/how-to-share-an-image-on-facebook-in-android/ […]
Aman Dhindsa
hi @Elisha Chirchir
thanks for example but this code does not work on my side… please help me..
Elisha Chirchir
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
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
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
Please give me a moment to try out your code then respond accordingly.
Aman Dhindsa
i can share image using this code from my emulator. but i could not share image with android device..
quocviet
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
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;
Tiago
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
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?
Tiago
Hi, you can see my code project on my GitHub account: https://github.com/issuran/Filter-Share
Nothing to show when sharing a picture using facebook sdk android « news-Knowlage FeeD
[…] I’m trying to learn how to share a simple image using android and facebook SDK following this tutorial. […]
Gil Garibi
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
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!
edo
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 🙂
Ankit Kamboj
Hi Elisha, I want to share multiple images on Facebook at a time. How can i achieve it? Please help me.
Elisha Chirchir
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
birdun2013
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!
Law
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
}
});
Pradeep Bishnoi
Hii
Great Thanks Dear very helpfull
Best of luck for further post
Pradeep Bishnoi
DoÄŸanay
Hİ Elisha thanks for tutorial is the best I ‘ ve ever seen about this topic.
Ali AKRAM
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
That is weird behavior unless the Facebook Graph API has changed!
Yoonnyung Choi
I have the exact same problem too!!
jatin bansal
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);
}
}
Zeeshan Shahid
what modifications I have to do in this code if want to share a link or status on facebook??
Hardik miyani
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
Razia
Hii Elisha
Is it possible to multiple images on facebook??
Razia
Hii Elisha
Is it possible to share multiple images on facebook??
Elisha Chirchir
I am not absolutely sure on this; but I will get back to you when I find out!
chandra boyilla
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…..
kinjal
it ads in album instead of adding in upload post
Pál Matolay
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
You can share your repository here in the comments for others to use!
Sandeep Gupta
Getting this error : Unable to show the provided content via the web or the installed version of the Facebook app. Some dialogs are only supported starting API 14
sirisha
Hi Its very nice article and helpfull to everyone
Amandi
Hello sir,
I followed your code and ran the app, it actually ran but, couldn’t figure out where the shared image is on facebook. please what could have gone wrong sir?
kauhal raj singh
i m created a app where i used facebook and instagram packages(com.facebook.katana) and (com.instagram.android) its working on mobile version 5 and 6 but not working on nought(7+) version so what is the solution of its…..
Praveen Kumar
Any Way To UPload Gif to Facebook
testing
how to use ShareApi in share post for facebook account not show post Dialog