我正在开发一个在Facebook上分享一些信息的应用程序。为此,我这样做:
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
.setName(attraction.getName())
.setLink("http://developer.neosperience.com/")
.setDescription(attraction.getDescription())
.setRef(String.valueOf(id_attraction))
.setPicture(pictureURLtoShare)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
我的问题是我需要发送一个参数(id_attraction),所以当点击facebook的帖子时,它会打开我的应用程序并收到该参数。我认为setRef可以工作,但我收到null。 这就是我收到意图的方式:
AppLinkData appLinkData = AppLinkData.createFromActivity(this);
if (appLinkData != null) {
Bundle arguments = appLinkData.getArgumentBundle();
//appLinkData.
if (arguments != null) {
String targetUrl = arguments.getString("target_url");
if (targetUrl != null) {
Log.i("Activity FB", "Target URL: " + targetUrl);
}
}
}
答案 0 :(得分:1)
我不知道这是否是正确的方法,但我找到了解决方法。我使用'?'发送附加到网址的参数那么一切都在右边?将被浏览器忽略。
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
.setName(attraction.getName())
.setLink("http://developer.neosperience.com/?"+id_attraction)
.setDescription(attraction.getDescription())
.setPicture(pictureURLtoShare)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
然后我收到它:
AppLinkData appLinkData = AppLinkData.createFromActivity(this);
if (appLinkData != null) {
Bundle arguments = appLinkData.getArgumentBundle();
//appLinkData.
if (arguments != null) {
String targetUrl = arguments.getString("target_url");
if (targetUrl != null) {
String[] partOfUrl = targetUrl.split("\\?");
id_attraction = partOfUrl[1];
Log.i("Activity FB", "Target URL: " + targetUrl);
}
}
}