简体   繁体   English

如何从Firebase获取当前的用户个人资料图像和名称?

[英]How to get the current user profile image and name from Firebase?

Below is my Firebase structure image, 下面是我的Firebase结构图,

Firebase Structure 火力基地的结构

在此处输入图片说明

I will like to use the name and profile image of user for my Second Activity. 我想在“第二个活动”中使用用户的名称和个人资料图片。

Here how I did for my another app, 这是我为另一个应用程序所做的工作,

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
String name = user.getDisplayName();

And I later used the name in my TextView to use the current user name but here it didn't worked and besides I also needed the profile image too. 我后来用的name在我TextView使用当前用户名,但在这里没有工作,况且我也需要个人资料图片了。

So, How do I get the user image and name from above Firebase structure image to my Second activity layout TextView and ImageView and set the default text name and image if it returns null. 因此,如何从Firebase结构图像上方将用户图像和名称获取到我的Second Activity布局TextViewImageView并设置默认的文本名称和图像(如果返回的是null)。

I tried below but it didn't worked to 我在下面尝试过,但没有成功

public void setUserData(String name, String image) {

    ImageView userimage = (ImageView) findViewById(R.id.imageView);
    userimage.setImageURI(userimage);
}

Your url is a string not Uri. 您的网址是一个字符串,而不是Uri。 So, you need to fetch the image from the given url. 因此,您需要从给定的URL中获取图像。

You can use AsyncTask like: link 您可以使用AsyncTask之类的: link

or use Glide library to make async calls. 或使用Glide库进行异步调用。 Glide 滑行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM