【发布时间】: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