【问题标题】:Trouble with init branch.ioinit branch.io 有问题
【发布时间】:2017-11-07 07:23:39
【问题描述】:

我使用 branch.io 来处理应用程序链接。 AndroidManifest 具有分支 URI 方案的意图过滤器:

<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-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 的 LaunchMode 是 singleTask。我在应用程序中的 onCreate 中初始化分支:

Branch.getAutoInstance(this);

打开 AppLinkActivity 后,我得到实例并初始化会话:

Branch branch = Branch.getInstance(getApplicationContext());
   branch.initSession((referringParams, error) -> {
        LogFileUtil.writeLog("Finish init session");
        if (error == null) {
            //Кое что делаю
        } else {
           //Кое что делаю
        }
    }, this.getIntent().getData(), this);

当我通过 AppLink 打开我的应用程序时,引用参数不为空。我可以获得所需的数据。 但是当应用程序打开并且我从其他应用程序中单击 AppLink 时,引用参数是空的。我认为问题是初始化分支。我该如何解决?

【问题讨论】:

    标签: java android branch.io


    【解决方案1】:

    解决方案 - 您需要将 AppLinkActivity 类设为 main。此活动必须有一个更多的意图过滤器:

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    

    【讨论】:

      【解决方案2】:

      您需要确保在 AppLinkActivity 中覆盖 onNewIntent() 方法。这将确保返回相同的意图。

      将以下 sn-p 添加到您的 AppLinkActivity:

      @Override
      protected void onNewIntent(Intent intent) {
          this.setIntent(intent);
      }
      

      【讨论】:

      • 没有。问题不是因为这个。 onNewIntent 在我的课上。我之前回答了我的问题。
      • @osip_000 建议在 App 的第一个 Activity 中初始化 Branch,以确保每次都初始化 Branch。太好了,这解决了您的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 1970-01-01
      • 2018-05-17
      相关资源
      最近更新 更多