2
我正在整合facebook sdk 3.21.1,所有的事情都進展順利,但只有一個問題。 當我點擊分享按鈕時,它會提示我一個對話框(在FacebookDialog.ShareDialogBuilder的情況下)發佈的東西。如果我按Back按鈕,com.facebook.widget.WebDialog.OnCompleteListener的onCompleteMethod將被調用,並且我無法獲取該事件,或者它已成功發佈或按下按鈕。 因爲我想向用戶顯示確切的吐司消息。Facebook與Android應用程序集成
這是我的代碼: -
/**
* Handle Facebook Sharing
*
* Take Decision for sharing approach.
*/
private void handleFacebookSharing()
{
//Show Hash Key
showHashKey(this);
//Can Present Share Dialog(Facebook Application is installed or not)
boolean canPresentShareDialog = FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
if (canPresentShareDialog)
{
//Publish the Post Using the Share Dialog
FacebookDialog.ShareDialogBuilder shareDialogBuilder = new FacebookDialog.ShareDialogBuilder(ShareActivity.this);
//Set Link
shareDialogBuilder.setLink(ShareActivity.this.getString(R.string.share_link));
//Set Caption
shareDialogBuilder.setCaption(getString(R.string.share_caption));
//Set Description
shareDialogBuilder.setDescription(getString(R.string.share_description));
//Get Facebook Dialog
FacebookDialog facebookDialog = shareDialogBuilder.build();
//Track Pending Dialog Call
uiHelper.trackPendingDialogCall(facebookDialog.present());
}
else
{
if(activeSession == null || !activeSession.isOpened())
{
//Open Active Session
activeSession = Session.openActiveSession(this, true, statusCallback);
}
else
{
//Show Web Dialog
showWebDialog();
}
}
}
而且onActivityResult方法: -
uiHelper.onActivityResult(requestCode, resultCode, intent, new FacebookDialog.Callback()
{
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data)
{
//Show Toast
UIUtil.showToast(R.string.toast_message_share_error_posting);
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data)
{
//Show Toast
UIUtil.showToast(R.string.toast_message_share_success_post);
}
});