在以下功能中,我正在从Firebase云数据库中检索用户信息(用户名和生物)。但是,日志显示没有此类文档,这意味着该文档不存在。在主要活动中,文档已成功上传到数据库。难道是在上载文档之前执行了检索用户信息功能? 预先感谢!
以下代码来自SignupActivity:
private void retrieveProfileViaURLandUploadUserInfo (final String user, final String bioInfo) {
profileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
pathToProfile = uri.toString();
String UID = getUserID();
UserInfo.put(USERNAME, user);
UserInfo.put(BIO, bioInfo);
UserInfo.put(PROFILE_URL, pathToProfile);
Log.d(TAG, "Got UID");
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);
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.d(TAG, "retrieve profile image failure");
// pathToProfile = "uri download unsuccessful";
}
});
}
这在HomeActivity中
public void retrieveDisplayUserInfo() {
String UID = getUserID();
Log.d(TAG, UID);
mDocRef.collection("users").document(UID).get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
Log.d(TAG, "DocumentSnapshot data: " + document.getData());
String userName = document.getString(USERNAME);
String shortBio = document.getString(BIO);
String URL = document.getString(PROFILE_URL);
displayUserName = findViewById(R.id.usernameView);
displayUserName.setText(userName);
displayBio = findViewById(R.id.shortBio);
displayBio.setText(shortBio);
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
}
这是StackTrace
D/EmailPassword: createAccount:dfajlkj@fadf.com
I/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@9ba0059
I/m.test.testaut: IncrementDisableThreadFlip blocked for 7.062ms
W/m.test.testaut: Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
W/m.test.testaut: Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
W/m.test.testaut: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
W/m.test.testaut: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
W/m.test.testaut: Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, linking)
W/m.test.testaut: Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI)
W/m.test.testaut: Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (light greylist, reflection)
W/m.test.testaut: Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (light greylist, reflection)
W/m.test.testaut: Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (light greylist, linking)
Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (light greylist, linking)
W/m.test.testaut: Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
D/FirebaseAuth: Notifying id token listeners about user ( zx03kHuJ6Rh1ecQexeWMmwSHHZS2 ).
D/FirebaseAuth: Notifying auth state listeners about user ( zx03kHuJ6Rh1ecQexeWMmwSHHZS2 ).
D/UploadTask: Increasing chunk size to 524288
D/EmailPassword: createUserWithEmail:success
V/FA: Recording user engagement, ms: 11221
V/FA: Connecting to remote service
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@e040231
V/FA: Activity paused, time: 254213927
V/FA: onActivityCreated
W/m.test.testaut: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (light greylist, reflection)
Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection)
Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection)
Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (light greylist, reflection)
Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (light greylist, reflection)
Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
D/EmailPassword: zx03kHuJ6Rh1ecQexeWMmwSHHZS2
V/FA: Connection attempt already in progress
V/FA: Activity resumed, time: 254214029
D/EGL_emulation: eglMakeCurrent: 0xe8e40a20: ver 3 0 (tinfo 0xe8e4c590)
D/EGL_emulation: eglMakeCurrent: 0xe8e40a20: ver 3 0 (tinfo 0xe8e4c590)
D/EGL_emulation: eglMakeCurrent: 0xe8e40a20: ver 3 0 (tinfo 0xe8e4c590)
D/EGL_emulation: eglMakeCurrent: 0xe8e40a20: ver 3 0 (tinfo 0xe8e4c590)
D/EGL_emulation: eglMakeCurrent: 0xe8e40a20: ver 3 0 (tinfo 0xe8e4c590)
V/FA: Connection attempt already in progress
Connection attempt already in progress
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 4
D/EmailPassword: No such document
D/EmailPassword: upload profile image successful
V/FA: Inactivity, disconnecting from the service