java - 我没有从 Cloud Firestore 获取数据
问题描述
我正在设计一个社交媒体应用程序,其中我有其他人的个人资料数据,即用户名、用户邮箱和个人资料图片,并且我还在 dp 后面显示个人资料图片(作为背面图片)。我在云 Firestore 中有登录用户的所有数据,但是当我使用用户的电子邮件和密码登录时,未显示登录用户的数据意味着它没有从云 Firestore 获取数据。这是我的代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getCurrentUserDetails();
}
private void getCurrentUserDetails()
{
try {
CurrentUserEmail = getCurrentLoggedInUser();
if (CurrentUserEmail.equals("No user is logged in"))
{
Toast.makeText(this, "No user is logged in", Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, LoginPage.class));
finish();
}
else
{
header_progressBar.setVisibility(View.VISIBLE);
objectDocumentReference=objectFirebaseFireStore.collection("UserProfileData")
.document(CurrentUserEmail);
objectDocumentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
header_userName.setText(documentSnapshot.getString("username"));
header_userName.setAllCaps(true);
header_user_email.setText(CurrentUserEmail);
String linkOfProfileImage=documentSnapshot.getString("profileimageurl");
Glide.with(MainContentPage.this).load(linkOfProfileImage).into(header_ProfilePic);
Glide.with(MainContentPage.this).load(linkOfProfileImage).into(header_backgroundProfile);
header_progressBar.setVisibility(View.INVISIBLE);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainContentPage.this, "Loading User Details", Toast.LENGTH_SHORT).show();
}
});
}
}
catch (Exception e)
{
Toast.makeText(this, "MainContentPage:"+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
private String getCurrentLoggedInUser()
{
try
{
if(objectFirebaseAuth!=null)
{
return objectFirebaseAuth.getCurrentUser().getEmail().toString();
}
else
{
return "No user is logged in";
}
}
catch (Exception e)
{
Toast.makeText(this, "MainContentPage:"+e.getMessage(), Toast.LENGTH_SHORT).show();
return null;
}
}
解决方案
推荐阅读
- rails-admin - RailsAdmin:如何从自定义操作呈现不同的模型索引
- reactjs - 如何在材料表中自定义默认导出选项
- java - 将一张图像用于多个 ImageView 的最佳方法是什么
- flutter - 获取在 Flutter CustomScrollView 中可见/滚动的当前条子
- grafana - Grafana 仪表板:自动将日期变量设置为当前日期
- python - 如何将从 C++ 客户端套接字接收的二进制数据转换为 python 服务器套接字
- python - 高斯过程回归 - 解释行为
- python - Python傅里叶零填充
- azure - Azure VM 规模集 CustomScriptExtension 失败
- docker - 每次我想更改应用程序设置时,我是否必须重建我的 Docker 映像?