我正在阅读 Google 邀请:https : //developers.google.com/app-invites/android/guides/app以及 branch.io:https://dev.branch.io/recipes/content_sharing/android/#在你的安卓应用程序内路由到内容
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 方法中的意图:
@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 应用程序的意图?