I have added sharing functionality to Android app as described here https://developers.facebook.com/docs/android/share-dialog/#setup
But I have noticed that if user
private static FacebookCallback shareCallback = new FacebookCallback() {
@Override
public void onCancel() {
Log.d("HelloFacebook", "Canceled");
}
@Override
public void onError(FacebookException error) {
Log.d("HelloFacebook", String.format("Error: %s", error.toString()));
String title = this.getActivty().getString(R.string.error);
String alertMessage = error.getMessage();
showResult(title, alertMessage);
}
@Override
public void onSuccess(Sharer.Result result) {
Log.d("HelloFacebook", "Success!");
// 不为空,才分享成功
if (result.getPostId() != null) {
String title = this.getActivty().getString(R.string.success);
String id = result.getPostId();
String alertMessage = this.getActivty().getString(R.string.successfully_posted_post, id);
showResult(title, alertMessage);
}
}
private void showResult(String title, String alertMessage) {
new AlertDialog.Builder(this.getActivty())
.setTitle(title)
.setMessage(alertMessage)
.setPositiveButton(R.string.ok, null)
.show();
}
};
protected void onCreate (Bundle savedInstanceState)
{
shareDialog = new ShareDialog(this. getActivty());
shareDialog.registerCallback( callbackManager, shareCallback);
}