为了账号安全,请及时绑定邮箱和手机立即绑定

如何检索和显示配置文件图片 Android firebase?

如何检索和显示配置文件图片 Android firebase?

aluckdog 2021-10-13 16:26:59
如何使用uid检索和显示当前用户的个人资料图片?我已经使用 uid 将图像连接到用户 uid,但不确定如何检索和显示。这就是我将它上传到 Firebase 存储的方式mProfilePic.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View v) {            Intent intent = new Intent(Intent.ACTION_PICK);            intent.setType("image/*");            intent.setAction(Intent.ACTION_GET_CONTENT);            startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_INTENT);        }    });我让用户从那里的手机存储中单击一个图像视图,并使用当前登录的用户 uid 上传该图像。FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);    if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK && data != null && data.getData() != null){        mainImageURI = data.getData();        try {            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mainImageURI);            mProfilePic.setImageBitmap(bitmap);            final ProgressDialog proDialog = new ProgressDialog(HomeActivity.this);            proDialog.setTitle("Uploading...");            proDialog.show();            String userUid = FirebaseAuth.getInstance().getCurrentUser().getUid();            UploadTask uploadTask = FirebaseStorage.getInstance().getReference().child("newFolder").child(userUid).putFile(mainImageURI);            uploadTask                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {                        @Override                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {                        }                    })                    .addOnFailureListener(new OnFailureListener() {                        @Override                        public void onFailure(@NonNull Exception e) {                        }                    })
查看完整描述

2 回答

?
弑天下

TA贡献1818条经验 获得超8个赞

维护一个数据库,您可以在其中根据 uid 保存图像 url。然后使用该 url 从数据库中检索您的个人资料图片


查看完整回答
反对 回复 2021-10-13
  • 2 回答
  • 0 关注
  • 186 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号