从Android App将参数传递给Facebook App Link

时间:2016-04-11 11:18:10

标签: android facebook share

我正在使用以下代码与Facebook分享内容(例如文字,图片和应用链接):

第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>

这里是处理Activity中传入的应用程序链接的代码:

第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.
        }

如何在第1步中正确传递数据到应用链接网址,例如简单的字符串参数,然后返回第3步

1 个答案:

答案 0 :(得分:1)

万一有人有相同的问题&#34;我会发布我的解决方案:

当我从我的应用程序共享FB的链接时,我将URL中的参数传递给:

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

然后如果用户点击FB上的链接,那么我的应用程序启动,我得到如下参数:

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