【发布时间】:2017-05-22 11:55:07
【问题描述】:
我的问题类似于this recent question for iOS。
Firebase 动态链接在已存在该应用的设备上按预期工作,但当我从 Play 商店安装该应用(目前处于测试版通道中)时,我未能获得推荐。
具体来说,当从 PlayStore 测试版渠道安装应用时,AppInviteReferral.hasReferral(getIntent()) 返回 false。
根据链接的答案,动态链接大部分时间都有效,但可能存在未记录的边缘情况会导致它失败。我将重点介绍我的案例的具体内容,以便您帮助我找到我的设置中缺少的内容。
- 我刚刚将我的 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'
-
我的
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> SplashScreenActivity.java不是setContentView(int id)。它只是使用主题来显示启动画面,而应用程序的其余资源“加载”。我不知道这是否重要,但我把它放在那里。-
在应用程序启动之前,我会检查以确保应用程序具有所需的权限。
李>continueIntoApp()方法(我想不出更好的名称)在发现用户拥有所需权限时或在用户授予应用所需的所有四个权限后将用户带入应用程序。 -
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()。我仍然不确定何时应该将此值设置为true 或false。我也不知道,在从动态链接(autoLaunchDeepLink 为 false)全新安装后,Firebase 知道如何“启动动态链接”。
就动态链接实施而言。我的问题如上所述:当我已经安装了应用程序时,AppInviteReferral.hasReferral(getIntent()) 返回true,并且代码正常运行。当用户点击动态链接到 PlayStore 并下载 beta 版本时,AppInviteReferral.hasReferral(getIntent()) 返回false,并且不关注深度链接。
为什么会这样?我错过了什么?
【问题讨论】:
标签: firebase firebase-dynamic-links