I will be able to create deeplink and send it to facebook with all the relevant metadata:
TextView.OnClickListener inviteClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
.setCanonicalIdentifier("item/12345")
.setTitle("Suits")
.setContentDescription("Great suits here")
.setContentImageUrl("http://steezo.com/wp-content/uploads/2012/12/man-in-suit.jpg")
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
.addContentMetadata("picurl", "http://steezo.com/wp-content/uploads/2012/12/man-in-suit.jpg");
LinkProperties linkProperties = new LinkProperties()
.setChannel("facebook")
.setFeature("sharing")
.addControlParameter("$desktop_url", "http://www.yahoo.com")
.addControlParameter("$ios_url", "http://www.microsoft.com");
ShareSheetStyle shareSheetStyle = new ShareSheetStyle(PlaceDetailsActivity.this, "Check this out!", "This stuff is awesome: ")
.setMoreOptionStyle(getResources().getDrawable(android.R.drawable.ic_menu_search), "Show more")
.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.EMAIL);
branchUniversalObject.showShareSheet(PlaceDetailsActivity.this,
linkProperties,
shareSheetStyle,
new Branch.BranchLinkShareListener() {
@Override
public void onShareLinkDialogLaunched() {
}
@Override
public void onShareLinkDialogDismissed() {
}
@Override
public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {
Log.e("LinkShared", "success");
}
@Override
public void onChannelSelected(String channelName) {
}
});
branchUniversalObject.generateShortUrl(PlaceDetailsActivity.this, linkProperties, new Branch.BranchLinkCreateListener() {
@Override
public void onLinkCreate(String url, BranchError error) {
if (error == null) {
Log.i("MyApp", "got my Branch link to share: " + url);
}
}
});
}
};
What I can’t do is make sure that when I click on the link it goes to the correct action in my application. I watched the guide carefully, but at points I found the manual a little vague - https://dev.branch.io/references/android_sdk/#branch-universal-object-for-deep-links-content-analytics-and-indexing .
In the activity I want to trigger, I put this in the manifest:
<activity
android:name=".SuitActivity"
android:label=""
android:windowSoftInputMode="adjustResize">
<meta-data android:name="io.branch.sdk.auto_link_keys_6" android:value="picurl" />
</activity>
Inside the SuitActivity class, I add the following:
@Override
protected void onResume() {
super.onResume();
if (Branch.isAutoDeepLinkLaunch(this)) {
try {
action.setPicurl(Branch.getInstance().getLatestReferringParams().getString("picurl"));
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("nondeeplink","Launched by normal application flow");
}
}
, , , Facebook SuitActivity MainActivity, , , . , MainActivity.
, , :
2-16 19:44:38.019 24086-24086/com.example I/MyApp: got my Branch link to share: https://bnc.lt/cByh/7d3u8enomp
12-16 19:44:38.021 24086-24129/com.example I/BranchSDK: posting to https://api.branch.io/v1/url
12-16 19:44:38.021 24086-24129/com.example I/BranchSDK: Post value = {
"identity_id": "20569XXX",
"device_fingerprint_id": "20519XXX",
"session_id": "2057XXX",
"tags": [],
"alias": "",
"channel": "Add to Facebook",
"feature": "sharing",
"stage": "",
"data": "{\"$og_title\":\"Suits\",\"$canonical_identifier\":\"item\\\/12345\",\"$keywords\":[],\"$og_description\":\"Great suits here\",\"$og_image_url\":\"http:\\\/\\\/steezo.com\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/man-in-suit.jpg\",\"$content_type\":\"\",\"$exp_date\":\"0\",\"picurl\":\"http:\\\/\\\/steezo.com\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/man-in-suit.jpg\",\"$desktop_url\":\"http:\\\/\\\/www.yahoo.com\",\"$ios_url\":\"http:\\\/\\\/www.microsoft.com\",\"source\":\"android\"}",
"sdk": "android1.10.1",
"retryNumber": 0,
"branch_key": "key_test_XXX"
}
EDIT:
GitHub : https://github.com/Winghin2517/BranchIOTestDeepLink
:
MainActivity FAB - , Android Studios. FAB, Branch.io facebook, ..
SecondActivity - , facebook facebook , SecondActivity. , facebook , , MainActivity.
, , branch.IO , , XXX:
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_XXX" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_XXX" />
!