I'm using Facebook Android SDK 4.+ to share photo by a button click in my app.
When user click the button, it will open the Facebook share photo page. After posting the photo I want to show alertbox which telling that photo has succesfully posted.
I've been using this
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.setShareHashtag(new ShareHashtag.Builder()
.setHashtag(hastag).build())
.build();
ShareDialog.show(SellingActivity.this,content);
By putting the alertbox after sharedialog.show didn't seem work. It would end up showed after button clicked, then facebook share photo page would show up after that.
If you use this method of share ShareDialog.show(SellingActivity.this,content);
there won't be anycallback. Look at there documention -
/**
* Helper to show the provided {@link com.facebook.share.model.ShareContent} using the provided
* Fragment. No callback will be invoked.
*
* @param fragment android.support.v4.app.Fragment to use to share the provided content
* @param shareContent Content to share
*/
public static void show(
final Fragment fragment,
final ShareContent shareContent) {
show(new FragmentWrapper(fragment), shareContent);
}
If you want callback then we have to use CallbackManager and we need to register for Callback.
In summary below is what you need to do -
Create CallbackManager
CallbackManager callbackManager = CallbackManager.Factory.create();
Create ShareDialog
ShareDialog shareDialog = new ShareDialog(activity or fragment);
Register for callback
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { } @Override public void onCancel() { } @Override public void onError(FacebookException error) { } });
@Override public void onActivityResult(int requestCode, int resultCode, Intent data { super.onActivityResult(requestCode,resultCode, data); callbackManager.onActivityResult(requestCode,resultCode, data); }