我使用branch.io 来处理应用程序链接。 AndroidManifest 有针对 Branch URI 方案的 Intent 过滤器:
<intent-filter>
<data android:scheme="***" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
AndroidManifest 还具有应用程序链接的 Intent 过滤器:
<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="***.app.link" />
<data
android:host="***-alternate.app.link"
android:scheme="https"/>
<data
android:host="***.test-app.link"
android:scheme="https"/>
<data
android:host="***-alternate.test-app.link"
android:scheme="https"/>
AppLinkActivity 的启动模式为 singleTask。我在 onCreate 中的应用程序中初始化分支:
Branch.getAutoInstance(this);
打开 AppLinkActivity 后,我获取实例并初始化 session :
Branch branch = Branch.getInstance(getApplicationContext());
branch.initSession((referringParams, error) -> {
LogFileUtil.writeLog("Finish init session");
if (error == null) {
//Кое что делаю
} else {
//Кое что делаю
}
}, this.getIntent().getData(), this);
当我通过 AppLink 打开我的应用程序时,referencingParams 不为空。我可以获得所需的数据。但是,当应用程序打开并且我从其他应用程序单击 AppLink 时,referencingParams 为空。我认为问题出在 init 分支上。我该如何修复它?
您需要确保重写 AppLinkActivity 中的 onNewIntent()
方法。这将确保返回相同的 Intent 。
将以下代码段添加到您的 AppLinkActivity:
@Override
protected void onNewIntent(Intent intent) {
this.setIntent(intent);
}
我是一名优秀的程序员,十分优秀!