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.
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?"
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:
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 );
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With