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

如何使用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();


@Override

protected 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) {


                        }

                    })

aluckdog
浏览 187回答 2
2回答

弑天下

维护一个数据库,您可以在其中根据 uid 保存图像 url。然后使用该 url 从数据库中检索您的个人资料图片
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python