Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook android shareDialog closes after opening

Following THIS I'm using facebook sdk in my android application and for test I've added below code to my MainActivity:

CallbackManager callbackManager;
ShareDialog shareDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);

    callbackManager = CallbackManager.Factory.create();
    shareDialog = new ShareDialog(this);

    if (ShareDialog.canShow(ShareLinkContent.class)) {
        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentTitle("Hello Facebook")
                .setContentDescription(
                        "The 'Hello Facebook' sample  showcases simple Facebook integration")
                .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
                .build();

        shareDialog.show(linkContent);
    }
}

and I've added the following steps in my manifest:

<uses-permission android:name="android.permission.INTERNET"/>

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

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

<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" />

and when I test the shareDialog pops up and suddenly it closes itself.

like image 773
arash moeen Avatar asked May 10 '15 15:05

arash moeen


3 Answers

You need to make your app "Public".

Go to the "Status and Review" section in your app settings, and turn on the option "Do you want to make this app and all its live features available to the general public?"

like image 52
Ming Li Avatar answered Oct 28 '22 11:10

Ming Li


You need to specify a Mode on the show() method. Between FEED,
NATIVE, WEB and AUTOMATIC the most convenient one is the last one (AUTOMATIC) because it collects data straight from Facebook app so you don't have to log in, but some times it closes unexpectandly.. Generally here is what i thing:

  • FFED: 1)Works through Google Chrome, 2)old design 3)need to log in
  • NATIVE: 1)Posts using the facebook app, no need for extra login
  • WEB: Similar to FEED but with different UI
  • AUTOMATIC: (Sometimes on start it closes immediately..) 1)uses only facebook app 2) no need to re-login 3)shares like any other share Take a better look here:https://developers.facebook.com/docs/reference/android/current/class/ShareDialog.Mode/ So i would suggest WEB, cause it works always:

    shareDialog.show(linkContent, ShareDialog.Mode.WEB );

like image 44
Panos K. Avatar answered Oct 28 '22 12:10

Panos K.


The problem was with the phone I was testing the application on, as it seems you have to be logged into facebook application using the Facebook account who is marked as developer which your application is registered under, then it will work as it supposed to and I assume for later use when you use the release ssh key it will work on any device with any account.

like image 2
arash moeen Avatar answered Oct 28 '22 11:10

arash moeen