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?
沒有人有一個想法? :) – Sin