Search code examples
androidfacebookfbsdksharedialog

ShareDialog dismiss immediately


I 'm trying to add a ShareFacebook button in my android app.

The code works when I use my FB account, the one I used with Facebook Developer Console and I can share the link on my FB with no problem.

But, when I tested the app with an other FB account, the share dialog appears and disappeares very fast.

I have no clue why, any help?

Here's my code:

facebook.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

                ShareDialog shareDialog = new ShareDialog(ScoreActivity.this);

                if (ShareDialog.canShow(ShareLinkContent.class)) {
                    ShareLinkContent linkContent = new ShareLinkContent.Builder()
                            .setContentUrl(Uri.parse("..."))
                            .build();

                    shareDialog.show(linkContent);


                }

        }

    });

Since I can share with my Fb then I guess the code is fine, So it's probably a configuration or a parameter issues, but I have no idea where to start. Any help?


Solution

  • Have you found any stack trace?
    You must look if you have initialized facebook SDK or not

    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    shareDialog = new ShareDialog(this);
        // this part is optional
    shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { ... });
    

    and if it is showing, and dismissing, then there must be

    <provider android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
          android:name="com.facebook.FacebookContentProvider"
          android:exported="true"/>