2016-04-11 150 views
2

我用下面的代碼共享內容(如文字,圖像和應用程序的鏈接)至Facebook:傳遞參數給Facebook應用鏈接從Android應用程序

第1步:

public void setupFacebookShareIntent() { 

    ShareDialog shareDialog; 

    FacebookSdk.sdkInitialize(getApplicationContext()); 
    shareDialog = new ShareDialog(this); 

    ShareLinkContent linkContent = new ShareLinkContent.Builder() 
      .setContentTitle(title) 
      .setContentDescription(
        text1+ " " +text2) 
      .setContentUrl(Uri.parse("http://example/folder")) 
      .setImageUrl(Uri.parse(path1)) 
      .build(); 

    shareDialog.show(linkContent); 
} 

另外這裏該應用鏈接的元數據:

步驟2:

<html> 
<head> 
    <meta property="al:android:url" content="sharesample://story/1234"> 
    <meta property="al:android:package" content="com.mypackage"> 
    <meta property="al:android:app_name" content="ShareSample"> 
    <meta property="og:title" content="example page title" /> 
    <meta property="og:type" content="website" /> 
</head> 
<body> 
</body> 
</html> 

而這裏的代碼來處理活動進入應用程序鏈接:

第3步:

Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent()); 

     if (targetUrl != null) { 

      // If you need to access data that you are passing from the meta tag from your website or from opening app you can get them from AppLinkData. 
      Bundle applinkData = AppLinks.getAppLinkData(getIntent()); 
      String id = applinkData.getString("id"); 

      // You can also get referrer data from AppLinkData 
      Bundle referrerAppData = applinkData.getBundle("referer_app_link"); 

     } else { 
      // Not an applink, your existing code goes here. 
     } 

我怎樣才能將數據傳遞給應用程序鏈接的URL在步驟1中正確,如簡單字符串參數然後回到步驟3

+0

沒有人有一個想法? :) – Sin

回答

1

萬一有人有同樣的「問題」,我會後我的解決方案:

當我分享我的應用程序FB的鏈接我通過帕拉姆在URL這樣的:

http://my-app.com/xxxx/xxx.php?id=10 

然後如果用戶點擊FB的鏈接,然後我的應用程序啓動和我得到的參數如下:

Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent()); 
String s = targetUrl.getQueryParameter("id"); 
+0

非常感謝罪。由於我使用Facebook應用程序鏈接服務,所以真的想知道我怎麼能通過它的論點。但是你的解決方案很完美。 (y)的 –

相關問題