2014-11-05 181 views
1

我正在開發一個應用程序,它在Facebook中共享一些信息。對於我這樣做:從Facebook鏈接打開應用程序

if (FacebookDialog.canPresentShareDialog(getApplicationContext(), 
      FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { 
    // Publish the post using the Share Dialog 
     FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) 
     .setName(attraction.getName()) 
     .setLink("http://developer.neosperience.com/") 
     .setDescription(attraction.getDescription()) 
     .setRef(String.valueOf(id_attraction)) 
     .setPicture(pictureURLtoShare) 
     .build(); 
     uiHelper.trackPendingDialogCall(shareDialog.present()); 
    } 

我的問題是我需要發送一個參數(id_attraction),所以當從Facebook帖子被點擊它會打開我的應用程序,我收到的參數。我認爲setRef會工作,但我收到null。 這是我收到的意圖:

AppLinkData appLinkData = AppLinkData.createFromActivity(this); 
if (appLinkData != null) { 
    Bundle arguments = appLinkData.getArgumentBundle(); 
    //appLinkData. 
    if (arguments != null) { 
     String targetUrl = arguments.getString("target_url"); 
     if (targetUrl != null) { 
      Log.i("Activity FB", "Target URL: " + targetUrl); 
     } 
    } 
} 

回答

1

我不知道這是否是這樣做的正確的方式,但我發現了一個解決方法。我使用'?'發送附加到網址的參數所以一切都在右邊?將被瀏覽器忽略。

if (FacebookDialog.canPresentShareDialog(getApplicationContext(), 
      FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { 
    // Publish the post using the Share Dialog 
     FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) 
     .setName(attraction.getName()) 
     .setLink("http://developer.neosperience.com/?"+id_attraction) 
     .setDescription(attraction.getDescription()) 
     .setPicture(pictureURLtoShare) 
     .build(); 
     uiHelper.trackPendingDialogCall(shareDialog.present()); 
    } 

,然後我收到這樣的:

AppLinkData appLinkData = AppLinkData.createFromActivity(this); 
if (appLinkData != null) { 
    Bundle arguments = appLinkData.getArgumentBundle(); 
    //appLinkData. 
    if (arguments != null) { 
     String targetUrl = arguments.getString("target_url"); 
     if (targetUrl != null) { 
      String[] partOfUrl = targetUrl.split("\\?"); 
      id_attraction = partOfUrl[1]; 
      Log.i("Activity FB", "Target URL: " + targetUrl); 
     } 
    } 

}

相關問題