【发布时间】:2016-04-11 11:18:09
【问题描述】:
我正在使用以下代码向 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 步中正确地将数据传递给应用链接 url,例如简单的字符串参数,然后在 第 3 步中返回?
【问题讨论】:
-
没人知道吗? :)