【问题标题】:Android: Using Branch.io to generate deeplinks and Google Invites for content sharingAndroid:使用 Branch.io 生成深度链接和 Google 邀请以进行内容共享
【发布时间】:2015-10-23 10:07:48
【问题描述】:

我正在阅读 Google Invites:https://developers.google.com/app-invites/android/guides/app 和 branch.io:https://dev.branch.io/recipes/content_sharing/android/#routing-to-content-within-your-android-app

Google Invites 似乎在内容共享方面表现出色,它提供了一个界面,可以从 Google 中选择您想要向您的应用发送深层链接的所有人。

Branch.io 似乎擅长生成深层链接,并且它们的短网址将在其“嵌入键/值深层链接元数据”中包含应用所需的所有数据。

Branch.io 也有一个内置的“本地共享表”,但我认为它不如 Google Invites 先进/好。

我想使用带有 Google 邀请界面的 Branch.io 深层链接进行内容共享。

我正在努力将两者合并。

当有人点击 Google Invites 链接时,Android 应用打开,在 onCreate 方法中,运行以下代码来拦截意图:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // ...

    if (savedInstanceState == null) {
        // No savedInstanceState, so it is the first launch of this activity
        Intent intent = getIntent();
        if (AppInviteReferral.hasReferral(intent)) {
            // In this case the referral data is in the intent launching the MainActivity,
            // which means this user already had the app installed. We do not have to
            // register the Broadcast Receiver to listen for Play Store Install information
            launchDeepLinkActivity(intent);
        }
    }
}

Branch.io 告诉 android 在 onStart 方法中拦截 Intent:

@Override
public void onStart() {
    super.onStart();

    Branch branch = Branch.getInstance();

    // If NOT using automatic session management
    // Branch branch = Branch.getInstance(getApplicationContext());

    branch.initSession(new BranchReferralInitListener(){
        @Override
        public void onInitFinished(JSONObject referringParams, Branch.BranchError error) {
            if (error == null) {
                // params are the deep linked params associated with the link that the user clicked before showing up
                // params will be empty if no data found
                String pictureID = referringParams.optString("picture_id", "");
                if (pictureID.equals("")) {
                    startActivity(new Intent(this, HomeActivity.class));
                }
                else {
                    Intent i = new Intent(this, ViewerActivity.class);
                    i.putExtra("picture_id", pictureID);
                    startActivity(i);
                }
            } else {
                Log.e("MyApp", error.getMessage());
            }
        }
    }, this.getIntent().getData(), this);
}

如果我同时使用 Branch.io 和 Google Invites,我应该使用哪个代码来拦截在我点击深层链接时会启动 android 应用程序的意图?

【问题讨论】:

    标签: android google-app-invites branch.io


    【解决方案1】:

    我将分支 SDK 放入 google 的应用邀请示例并尝试了一些操作。似乎您无法将分支 URL 作为深层链接提供给 AppInviteInvitation IntentBuilder,而不会将链接转换为谷歌深层链接。您可以将消息本身设置为分支 URL,setMessage(url),并可能为深层链接提供 NULL URI,但这有点生硬。我自己试过了,电子邮件功能可以使用一半,但发短信没有。

    在没有分享表的情况下生成和分享分支链接的默认方式如下:

    BranchShortLinkBuilder shortUrlBuilder = new BranchShortLinkBuilder(MainActivity.this)
            .addTag("tag1")
            .addTag("tag2")
            .setChannel("channel1")
            .setFeature("feature1")
            .setStage("1")
            .addParameters("name", "test name") // deeplink data - anything you want!
            .addParameters("message", "hello there with short url")
            .addParameters("$og_title", "this is a title")
            .addParameters("$og_description", "this is a description")
            .addParameters("$og_image_url", "https://imgurl.com/img.png");
    
    // Get URL Asynchronously
    shortUrlBuilder.generateShortUrl(new Branch.BranchLinkCreateListener() {
        @Override
        public void onLinkCreate(String url, BranchError error) {
            if (error != null) {
                Log.e("Branch Error", "Branch create short url failed. Caused by -" + error.getMessage());
            } else {
                Log.i("Branch", "Got a Branch URL " + url);
    
                Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
                        .setMessage(url)
                        .setDeepLink(Uri.parse(url))
                        .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
                        .build();
                startActivityForResult(intent, REQUEST_INVITE);
    
    
            }
        }
    });
    

    至于应该使用哪个来拦截intent:使用Branch.initSession作为Branch链接,使用AppInviteReferral.hasReferral(intent)作为google链接。为了更好地共享对话而将服务交织在一起并不是我要采取的方向。相反,使用带有自定义共享对话框的分支链接(它们通过安装比 Android SDK 更快地传递数据),有很多方法可以构建自定义对话框,google around / checkout github。

    如果您有任何其他问题或需要更多信息,请告诉我,我很乐意为您提供帮助。

    【讨论】:

    • 感谢您的帮助。这是有用的信息。 Facebook App Invites 作为内容共享机制是否与 Branch.io 更好地集成?
    • 我刚刚将 FB SDK 放到了一个带有 Branch 的应用程序中。发出了一些邀请,但似乎什么都没有显示给人们,没有推送通知,我什至不确定 FB 的应用程序邀请在哪里。应用邀请的转化率 -> 注册非常糟糕,我再次建议使用自定义共享对话框。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多