我有一个使用Branch.io的应用程序,并且正在更新它以支持即时应用程序。这一变化的一部分将需要使用应用程序链接导航从一个应用程序的一部分到另一个。
我打开的活动被配置为使用Branch.io (例如,在https://dev.branch.io/marketing-channels/android-instant-apps/guide/中使用指令),并在它的onStart()方法中包括以下内容。但是,我并没有看到我在referringParams中的深层链接中包含的参数。
Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
Log.d("Branch", "onInitFinished() with deep link data: " + referringParams);
}
});我是否需要触发分支链接的打开,特别是从Android代码开始工作呢?
顺便说一句,上面的referringParams确实显示了+clicked_branch_link是false。
更新
只是为了澄清几件事。例如,我正在尝试使用app深度链接从ActivityA启动ActivityA。例如,ActivityB包括<intent-filter>,如https://dev.branch.io/marketing-channels/android-instant-apps/guide/中所描述的。在ActivityA中,我目前正尝试按如下方式打开/创建Branch.io链接(例如,在android-instant-apps示例中也直接形成了链接,但这不被视为“分支链接”)
HashMap<String, String> metadata = new HashMap<>();
metadata.put(PARAM, param);
BranchUniversalObject branchUniversalObject = new BranchUniversalObject().addContentMetadata(metadata);
LinkProperties linkProperties = new LinkProperties();
branchUniversalObject.generateShortUrl(context, linkProperties, (url, error) -> {
if (error == null) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(intent);
}
});如果我试图打开(由generateShortUrl)直接在设备上生成的url (例如,单击链接),那么ActivityB就启动了,我看到了包含在initSession回调中的param。如果我尝试使用上面的代码打开它(在ActivityA和ActivityB之间导航,那么ActivityB就会启动,但是不要得到params ( +clicked_branch_link是false) )
发布于 2017-10-21 00:28:09
如果您想深入链接到另一个即时应用程序 apk的新功能,那么分支现在不支持这个功能了。
如果您试图从活动A打开一个新功能中的活动B,从安装的应用程序中的另一个功能获得深度链接,您可以通过以下方式实现它。
ActivityA.java
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("yourBranchLink"));
intent.putExtra("branch","yourBranchLink");
intent.putExtra("branch_force_new_session",true);希望这能有所帮助
发布于 2017-10-09 17:28:01
为了用支持Instant应用程序的Android应用程序配置分支SDK,您可以遵循以下步骤:
1.初始化分支SDK,在应用程序类的()方法中初始化分支SDK。如果你计划在安装后从你的安卓即时应用程序深入链接到你的整个安卓应用程序,你将需要添加行enablePlayStoreReferrer。这增加了初始化的延迟,以等待Google Play Referrer,这可能会占用更多的时间。
public void onCreate() {
super.onCreate();
// This is needed to deferred deep link from an Android Instant App to a full app
// It tells the Branch initialization to wait for the Google Play Referrer before proceeding.
Branch.enablePlayStoreReferrer(1000L);
// Initialize the Branch SDK
Branch.getAutoInstance(this);
}2.添加分支密钥并注册安装引用程序
即时应用程序可能会相当混乱,因为有许多不同的清单,但您希望找到包含您的应用程序标记的报表。确保在这里定义了应用程序类名,然后在应用程序元素中指定分支键。
<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:supportsRtl="true"
android:name=".MyApplication">
<!-- Set to true to use Branch_Test_Key -->
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_app_live_key" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_app_test_key" />
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>3.将分支链接配置为Android
假设您已经为Android应用程序配置了分支链接,那么下一步就是在应用程序标记中添加App支持的意图过滤器。确保用链接域替换xxxx。(如果您还没有将完整的本地应用程序配置为使用分支作为Android链接,则可以按照提到的这里和这里步骤进行操作。)
<application
......
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="xxxx.app.link" />
<data android:scheme="https" android:host="xxxx-alternate.app.link" />
</intent-filter>
</application>4.检索分支深链数据
在活动中添加分支initSession,这些活动被配置为通过单击链接打开以接收深层链接参数。这将从引用链接返回深度链接数据。
protected void onStart() {
super.onStart();
Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
Log.d("Branch","onInitFinished() with deep link data: " + referringParams);
}
});
}5.配置从即时应用程序到完整应用程序的深度链接
为了将刚刚进入即时应用程序的用户转换为完整的本地应用程序,分支SDK提供了检查应用类型和完全应用转换的方便方法。这消除了对Google支持SDK ('com.google.android.instantapp')的依赖。以下是一些方法:
Branch.isInstantApp()
这种方便的方法检查当前版本的应用程序运行是即时应用程序还是完全Android应用程序
Branch.showInstallPrompt()
此方法显示了完整Android应用程序的安装提示,允许您在安装过程中传递分支将深层数据引用到完整应用程序的简单方法。
https://stackoverflow.com/questions/46618439
复制相似问题