【发布时间】:2020-05-14 13:10:56
【问题描述】:
程序员,我对 android studio 和 java 很陌生,在这种情况下,我正在尝试上传检索到的用户信息并将它们存储在 firebase 数据库中。检索过程成功,登录后可以看到检索URL。但是,String pathToProfile 没有分配 URL,当我检查日志时,它为空。提前致谢!
全局声明:
String pathToProfile;
Map<String, Object> UserInfo = new HashMap<>();
获取下载地址的功能
// retrieved URL should be saved in user document
private void retrieveProfileViaURL () {
profileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
pathToProfile = uri.toString();
UserInfo.put(PROFILE_URL, pathToProfile);
Log.d(TAG, "retrieve profile image successful" + pathToProfile);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.d(TAG, "retrieve profile image failure");
// pathToProfile = "uri download unsuccessful";
}
});
}
上传用户信息到firebase的功能
private void uploadUserInfo(String user, String bioInfo) {
// CollectionReference users = db.collection("users");
String UID = getUserID();
retrieveProfileViaURL();
// UserInfo.put(USERID, UID);
UserInfo.put(USERNAME, user);
UserInfo.put(BIO, bioInfo);
mDocRef.collection("users").document(UID).set(UserInfo)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(USER_INFO, "Document has been saved");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(USER_INFO, "Document was not saved!", e);
}
});
}
【问题讨论】:
-
“全局声明”实际声明在哪里? Java 中没有所谓的“全局”变量。
标签: java android google-cloud-firestore firebase-storage