我目前正在尝试按照 [docs][1] 在我的 android 项目中使用 firebase remote,我正处于必须获取我的值的地步,但是当我从字面上看时它一直给我一个错误复制粘贴文档中的代码(参见下面的代码)。它一直说“无法解析方法 addOnCompleteListener”,但由于我不太了解应该在函数内部编写什么,所以我似乎无法解决问题。
private void fetchConfig() {
mFirebaseRemoteConfig.fetchAndActivate()
.addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
boolean updated = task.getResult();
Log.d(TAG, "Config params updated: " + updated);
Toast.makeText(MainActivity.this, "Fetch and activate succeeded",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Fetch failed",
Toast.LENGTH_SHORT).show();
}
displayWelcomeMessage();
}
});
}
此外,我目前正在我的 build.gradle 中使用这些依赖项:
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-config:19.0.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.3.1'
implementation 'com.google.firebase:firebase-core:17.0.1'
我真的不知道我必须为这些依赖项采用什么版本,因为我使用的 API 级别非常低。这是一项学校作业,要求 min api 16,所以这是我在创建项目时选择的。但无论如何有人知道问题可能是什么吗?或者有人可以向我解释这部分应该为我的 firebase 配置做什么吗?
最佳答案
有时问题出在 Firebase 实现版本上,请尝试更改为该版本。
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-config:19.1.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.3.1'
implementation 'com.google.firebase:firebase-core:17.2.1'
关于java - 你应该在 addOnCompleteListener 里面写什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59478829/