2016-04-11 99 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)的 –

相关问题