In my project there is a possibility to post photo to Facebook using ShareDialog and SharePhotoContent as it represented in Facebook docs. I need to know if posting was successful or not, but onSuccess or onError methods in FacebookCallback implementations are never called.
Here's my code:
Button shareFbButton;
ShareDialog shareDialog;
CallbackManager callbackManager;
final int FB_CALLBACK = 101;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//...
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(getActivity());
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.d("photo uri", "FR success: " + result.getPostId());
}
@Override
public void onCancel() {
Log.d("photo uri", "FB cancel");
}
@Override
public void onError(FacebookException e) {
Log.d("photo uri", "FB error: " + e.getMessage());
}
}, FB_CALLBACK);
//...
return alertDialog;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.share_fb_button:
if (ShareDialog.canShow(SharePhotoContent.class)) {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.build();
SharePhotoContent linkContent = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
shareDialog.show(linkContent, ShareDialog.Mode.AUTOMATIC);}
break;
}
}
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
if(requestCode == FB_CALLBACK)
shareFbButton.setEnabled(false);
}
I've tried to register callback with REQUEST_CODE and without, but there was no result in both cases.
My build.gradle:
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
}
AndroidManifest.xml:
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider933***********1"
android:exported="true" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
I need some help to solve this problem, maybe I'm doing something wrong. Thanks in advance. UPD: ShareDialog and FacebookCallback are implemented in DialogFragment.