[英]Firebase remote config condition by userId
I integrated Firebase into my Android project, to get a different parameter value for different application user. 我将Firebase集成到我的Android项目中,以便为不同的应用程序用户获取不同的参数值。 I did the following: 我做了以下事情:
Entered the following code to sign in the user from the application: 输入以下代码以从应用程序登录用户:
Task resultTask = 任务resultTask = \n firebaseAuth.signInWithEmailAndPassword("test1@gmail.com", password); firebaseAuth.signInWithEmailAndPassword(“test1@gmail.com”,密码);
firebaseRemoteConfig.fetch() firebaseRemoteConfig.fetch() \n .addOnCompleteListener(new OnCompleteListener() { .addOnCompleteListener(new OnCompleteListener(){\n @Override @覆盖\n public void onComplete(@NonNull Task task) { public void onComplete(@NonNull Task task){\n if (task.isSuccessful()) { if(task.isSuccessful()){\n // Once the config is successfully fetched it must be activated before newly fetched //成功获取配置后,必须在新提取之前激活它\n // values are returned. //返回值。\n firebaseRemoteConfig.activateFetched(); firebaseRemoteConfig.activateFetched();\n Log.d(TAG, firebaseRemoteConfig.getString("MyParameter")); Log.d(TAG,firebaseRemoteConfig.getString(“MyParameter”));\n } else { } else {\n Log.d(TAG, "fetch firebase remote config failed. Reason = " + task.getException()); Log.d(TAG,“获取firebase远程配置失败.Results =”+ task.getException());\n } }\n } }\n }); });
The result was that I always got the default value: DefaultValue 结果是我总是得到默认值: DefaultValue
What did I do wrong? 我做错了什么? What did I miss? 我错过了什么?
After some investigation I figured that Firebase Analytics and Firebase Authentication are 2 different modules which don't automatically inter-connect. 经过一番调查后,我发现Firebase Analytics和Firebase身份验证是2个不同的模块,不会自动互连。
Using Firebase Authentication did not automatically identify the user as part of the particular audience, as I expected. 正如我所料,使用Firebase身份验证并未自动将用户标识为特定受众的一部分。
I needed to tell Firebase Analytics, that the current user has the specific user ID, so it can match it to the relevant audience. 我需要告诉Firebase Analytics,当前用户具有特定的用户ID,因此可以将其与相关受众进行匹配。 I added the following code to the sign-in onComplete callback: 我将以下代码添加到登录onComplete回调中:
Task<AuthResult> resultTask =
firebaseAuth.signInWithEmailAndPassword("test1@gmail.com", password);
resultTask.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// Task completed successfully
if (task.isSuccessful()) {
firebaseAnalytics.setUserId(task.getResult().getUser().getUid());
} else {
Log.d(TAG, "signInWithEmail firebase failed");
}
}
});
The important line is: 重要的是:
firebaseAnalytics.setUserId(task.getResult().getUser().getUid());
Some things to note: 有些事情需要注意:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.