其他分享
首页 > 其他分享> > android – Branch.io:单击链接时深入链接到特定活动

android – Branch.io:单击链接时深入链接到特定活动

作者:互联网

我成功创建了一个深层链接并将其发布到Facebook,并附上了所有相关的元数据:

TextView.OnClickListener inviteClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
                // The identifier is what Branch will use to de-dupe the content across many different Universal Objects
                .setCanonicalIdentifier("item/12345")
                        // This is where you define the open graph structure and how the object will appear on Facebook or in a deepview
                .setTitle("Suits")
                .setContentDescription("Great suits here")
                .setContentImageUrl("http://steezo.com/wp-content/uploads/2012/12/man-in-suit.jpg")
                        // You use this to specify whether this content can be discovered publicly - default is public
                .setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
                        // Here is where you can add custom keys/values to the deep link data
                .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);
                }
            }
        });
    }
};

我没有成功做的是确保在点击链接时,它会转到我的应用程序中的正确活动.我密切关注了指南,但在某些方面我发现指南有点模糊 – https://dev.branch.io/references/android_sdk/#branch-universal-object-for-deep-links-content-analytics-and-indexing.

在我想要调用的活动中,我把它放在清单中:

    <activity
        android:name=".SuitActivity"
        android:label=""
        android:windowSoftInputMode="adjustResize">
        <meta-data android:name="io.branch.sdk.auto_link_keys_6" android:value="picurl" />
    </activity>

在SuitActivity类中,我输入以下内容:

@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.

当我在Branch上创建链接时,这是日志中返回的内容:

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"
                                                                                        }

编辑:

我现在甚至已经添加了一个GitHub示例供您测试:https://github.com/Winghin2517/BranchIOTestDeepLink

它包括两个活动:

>使用FAB的MainActivity – 它是通过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" />

谢谢!

解决方法:

Github repo现在是一个有关Branch.io的Android的工作示例,经过几天来回与branch.io来回联系我终于得到了它的工作:

https://github.com/Winghin2517/BranchIOTestDeepLink

如果您点击Facebook中的链接或您决定发送链接的位置,该应用将打开“SecondActivity”,而不是“MainActivity”.如果您从’SecondActivity’单击后退,它将关闭应用程序,因为onActivityResult方法将在’MainActivity’中使用正确的活动代码调用,而finish()方法在’MainActivity’中调用以关闭应用程序.

标签:android,deep-linking,branch-io
来源: https://codeday.me/bug/20190706/1397468.html