【问题标题】:Firebase Dynamic Links on Android do not survive installation processAndroid 上的 Firebase 动态链接无法在安装过程中继续存在
【发布时间】:2017-05-22 11:55:07
【问题描述】:

我的问题类似于this recent question for iOS

Firebase 动态链接在已存在该应用的设备上按预期工作,但当我从 Play 商店安装该应用(目前处于测试版通道中)时,我未能获得推荐。

具体来说,当从 PlayStore 测试版渠道安装应用时,AppInviteReferral.hasReferral(getIntent()) 返回 false

根据链接的答案,动态链接大部分时间都有效,但可能存在未记录的边缘情况会导致它失败。我将重点介绍我的案例的具体内容,以便您帮助我找到我的设置中缺少的内容。

  1. 我刚刚将我的 Firebase 库从 10.2.4 更新为 10.2.6。更改日志中的 Firebase Invites 库没有任何更改。

如果重要,这是我包含库的顺序

compile 'com.google.firebase:firebase-core:10.2.6'
compile 'com.google.firebase:firebase-messaging:10.2.6'
compile 'com.google.firebase:firebase-auth:10.2.6'
compile 'com.google.firebase:firebase-database:10.2.6'
compile 'com.google.firebase:firebase-invites:10.2.6'
  1. 我的SplashScreenActivity.java 既充当启动器活动,又充当接受和处理深层链接的活动。这是 AndroidManifest 中的活动声明

    <activity
        android:name=".ui.setup.SplashScreenActivity"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <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="deeplinks.myCompanyDomain.com"
                android:pathPrefix="/mobile"/>
        </intent-filter>
    </activity>
    
  2. SplashScreenActivity.java 不是setContentView(int id)。它只是使用主题来显示启动画面,而应用程序的其余资源“加载”。我不知道这是否重要,但我把它放在那里。

  3. 在应用程序启动之前,我会检查以确保应用程序具有所需的权限。 continueIntoApp() 方法(我想不出更好的名称)在发现用户拥有所需权限时或在用户授予应用所需的所有四个权限后将用户带入应用程序。

    李>
  4. continueIntoApp() 是在Firebase Dynamic Links Docs 上找到的所有代码的实现位置。我首先构建并连接一个GoogleApiClient

    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                    LogUtils.e("Deeplink connection failed");
                    LogUtils.e(connectionResult.getErrorMessage());
                    LogUtils.e(String.valueOf(connectionResult.getErrorCode()));
                }
            })
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(@Nullable Bundle bundle) {
                    LogUtils.d("Connected!");
                }
    
                @Override
                public void onConnectionSuspended(int i) {
                    LogUtils.e("Connection suspended!");
                }
            })
            .addApi(AppInvite.API)
            .build();
    
    googleApiClient.connect();
    

顺便说一句,动态链接文档假定开发人员已经知道如何设置GoogleApiClient。我没有。折腾了几天后,我偶然发现#connect() 方法实际上让GoogleApiClient 做了它应该做的事情。

之后,我检查AppInviteReferral 是否有推荐人。

    //boolean autoLaunchDeepLink = true;
    if(AppInviteReferral.hasReferral(getIntent())){
        LogUtils.d("Referral found!");
        AppInvite.AppInviteApi.getInvitation(googleApiClient, SplashScreenActivity.this, true)
                .setResultCallback(new ResultCallback<AppInviteInvitationResult>() {
                    @Override
                    public void onResult(@NonNull AppInviteInvitationResult appInviteInvitationResult) {

                        LogUtils.d("Processing appInviteInvitationResult...");

                        if(appInviteInvitationResult.getStatus().isSuccess()){
                            Intent intent = appInviteInvitationResult.getInvitationIntent();
                            String deepLink = AppInviteReferral.getDeepLink(intent);

                            LogUtils.d("Deeplink is " + deepLink);
                            AppConfig appConfig = new AppConfig(SplashScreenActivity.this);
                            appConfig.put(ModelKeys.TEMP_JOIN_BRANCH_DEEPLINK, deepLink);
                            startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
                            //parseDeeplink(deepLink);
                        }else {
                            LogUtils.d("No deeplink found!");
                            startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
                        }
                    }
                });
    }else {
        LogUtils.d("No referral found!");
        startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
    }

你会注意到我已经注释掉了autoLaunchDeepLink,并且默认情况下,将true 传递给AppInvite.AppInviteApi.getInvitation()。我仍然不确定何时应该将此值设置为truefalse。我也不知道,在从动态链接(autoLaunchDeepLinkfalse)全新安装后,Firebase 知道如何“启动动态链接”。

就动态链接实施而言。我的问题如上所述:当我已经安装了应用程序时,AppInviteReferral.hasReferral(getIntent()) 返回true,并且代码正常运行。当用户点击动态链接到 PlayStore 并下载 beta 版本时,AppInviteReferral.hasReferral(getIntent()) 返回false,并且不关注深度链接。

为什么会这样?我错过了什么?

【问题讨论】:

    标签: firebase firebase-dynamic-links


    【解决方案1】:

    我认为您没有遗漏任何内容 - Play 商店似乎没有为 Beta 频道安装发送 INSTALL_REFERRER 广播,并且它的引荐来源网址用作传递深层链接安装后的机制.

    如果您使用的是产品应用程序,它应该可以正常工作,但有点奇怪的是 Beta 版安装不支持该功能。

    【讨论】:

    • 我即将在我的应用程序中自己实现 Firebase 动态链接,所以我对这个问题没有真正的答案......我只是想指出我实际上是从将 SDK 调整到 Firebase,我从 Play 商店测试了我的 Beta 版 apk:即使从 Beta 频道也可以正确发送 Adjust INSTALL_REFERRER。
    • 我遇到了同样的问题,在我的 DEBUG 版本的应用程序上完美检测到动态链接,但是当我在 ALPHA 频道中发布我的应用程序的发布版本时,我无法接收动态链接在我的初始屏幕中...如果您找到了解决方案,请报告。
    • 谢谢伊恩。它现在完美运行。这个问题有点奇怪。
    • 嗨,我知道我有点晚了,但我遇到的问题与我的应用程序目前处于 Beta 版时完全相同。有没有办法手动发送 INSTALL_REFERRER 以在 Beta 阶段测试此功能?
    • @QuimBaget 您可以在 Android Studio 中更改运行/调试配置以启动 URL 而不是默认活动。这将帮助您在未安装应用程序时测试用例。我还没有找到在 Beta 阶段发送 INSTALL_REFERRER 的解决方案。
    【解决方案2】:

    有同样的问题。我们的问题是我们在 AndroidManifest.xml 中有两个几乎相似的意图过滤器,这导致 Google Play 失去了我们想要的意图。它没有显示“继续”按钮,而是将我们重定向到播放中的卸载/打开页面。

    建议合作 https://firebase.google.com/docs/dynamic-links/android/receive

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-08
      • 2018-10-22
      • 2018-12-13
      • 2013-09-11
      • 1970-01-01
      • 2021-12-06
      • 2022-10-18
      • 2021-08-08
      相关资源
      最近更新 更多