Reputation: 281
I'm developing an app that shares some information in facebook. For that I do this:
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());
}
My problem is I need to send a parameter (id_attraction), so when the post from facebook is clicked it will open my app and I receive that parameter. I thought that setRef would work but I receive null. This is how I receive the Intent:
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);
}
}
}
Upvotes: 1
Views: 546
Reputation: 281
I dont know if it's the correct way to do this but I found a workaround. I send the parameter attached to the url using '?' so everything on the right of ? will be ignored by the browser.
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());
}
and then I receive it like this:
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);
}
}
}
Upvotes: 1