【问题标题】:Android Branch IO deep link does not open my applicationAndroid Branch IO 深层链接无法打开我的应用程序
【发布时间】:2017-02-17 08:10:25
【问题描述】:

我用一个Activity 创建了一个简单的应用程序,清单如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="kz.ant.branchio">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name=".MyApp">

        <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_XXXXXXXXXXX" />

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

            <intent-filter>
                <data android:scheme="branchiotestapp" 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>
        </activity>

        <receiver android:name="io.branch.referral.InstallListener" android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

在我的key_live_XXXXXXXXXXX 中,我已经粘贴了我的仪表板实时密钥。

然后在我的应用程序中添加了这个:

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Branch.getAutoInstance(this);
    }
}

我的MainActivity 有这些代码行:

@Override
protected void onStart() {
    super.onStart();

    Branch branch = Branch.getInstance();
    branch.initSession(new Branch.BranchReferralInitListener(){
        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {
            if (error == null) {
                // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
                // params will be empty if no data found
                // ... insert custom logic here ...
            } else {
                Log.i("MyApp", error.getMessage());
            }
        }
    }, this.getIntent().getData(), this);
}

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

我的应用程序 URI 方案是 branchiotestapp://,据我了解,当用户单击此方案的链接时,它应该打开我的应用程序。然后我用这段代码创建了简单的 HTML 网页:

<html>
    <head>
        <title>Test</title>
    </head>

    <body>
        <a href="branchiotestapp://mysite.com">CLICK</a>
    </body>
</html>

当我使用手机浏览器打开此 HTML 并单击此链接时,我的 Android 应用程序即使已安装也无法打开

为什么会这样?我是否误解了 branch.io 的工作原理?

【问题讨论】:

    标签: android deep-linking branch.io


    【解决方案1】:

    这里的问题是您在网页上放置的链接。

    使用 Branch 时,您不会构建自己的意图字符串:您使用的是 Branch 链接。您可以在营销页面(此处:https://dashboard.branch.io/marketing)上从应用程序的分支仪表板创建分支链接;在您的移动应用程序中使用 Branch SDK 调用;或通过将查询参数附加到您的分支链接域(可以在仪表板的链接设置页面底部找到,此处为:https://dashboard.branch.io/settings/link)。各种方法的完整描述可以在这里找到:https://dev.branch.io/getting-started/creating-links/overview/

    关于您在网页上放置的特定意图字符串,您尚未定义任何意图过滤器或活动来处理“mysite.com”URI 路径。用“open”替换此 URI 路径可能会使链接正常工作,但我建议在这里创建分支链接作为最佳方法。

    【讨论】:

      【解决方案2】:

      从您的代码中,我可以看到您的活动缺少单任务启动模式,请分配

      android:launchMode="singleTask"
      

      在分支 io 集成中提到了,如果你也错过了任何其他东西,你可以看到 https://help.branch.io/developers-hub/docs/android-basic-integration

      需要单任务启动模式 单任务模式仅在 Activity Stack 中不存在 Main/Splash Activity 时实例化它。

      如果 Activity 存在于后台,则该 Activity 的每个后续 Intent 都会将其带到前台。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-19
        • 2016-06-26
        • 1970-01-01
        • 2016-05-10
        • 1970-01-01
        • 2016-05-07
        • 1970-01-01
        相关资源
        最近更新 更多