2014-12-20 204 views
2

我正在整合facebook sdk 3.21.1,所有的事情都進展順利,但只有一個問題。 當我點擊分享按鈕時,它會提示我一個對話框(在FacebookDialog.ShareDialogBu​​ilder的情況下)發佈的東西。如果我按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); 
     } 
    }); 

回答

0

傢伙花了很多的時間後,我發現了一個解決方案,我們可以檢查這個故事被取消或張貼通過使用這個代碼。

@Override 
    public void onComplete(PendingCall pendingCall, Bundle data) 
    { 
     //Get Native Dialog Did Complete 
     boolean didComplete = FacebookDialog.getNativeDialogDidComplete(data); 

     if(didComplete) 
     { 
      //Get Native Dialog Completion Gesture 
      String nativeDialogCompletionGesture = FacebookDialog.getNativeDialogCompletionGesture(data); 

      if (nativeDialogCompletionGesture == null || FacebookDialog.COMPLETION_GESTURE_CANCEL.equals(nativeDialogCompletionGesture)) 
      { 
       //Show Publish Cancel Toast 
       UIUtil.showToast(R.string.toast_message_share_publish_cancelled);            
      } 
      else 
      { 
       //Show Success Post Toast 
       UIUtil.showToast(R.string.toast_message_share_success_post); 
      } 
     } 
     else 
     { 
      //Show Publish Cancel Toast 
      UIUtil.showToast(R.string.toast_message_share_publish_cancelled); 
     } 
    } 

    @Override 
    public void onError(PendingCall pendingCall, Exception error, Bundle data) 
    { 
     //Show Toast 
     UIUtil.showToast(R.string.toast_message_share_error_posting); 
    }