首页 文章

图片网址未被推送到Firebase数据库

提问于
浏览
1

我有一个注册活动,要求用户图片 . 当从图库中选择图片时,我将图片推送到firebase存储,然后将下载URL推送到firebase数据库 . 图片不是推送到firebase存储,而是推送到firebase数据库 . 这是我的代码

cameraImageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/jpeg");
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PHOTO_PICKER);

            }
        });


        mFirebaseStorage = FirebaseStorage.getInstance();
        mChatPhotosStorageReference = mFirebaseStorage.getReference().child("profile_pic");

在我的OnActivityResult代码如下

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);



        if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK ) {
            filePath = data.getData();

            try {
                //getting image from gallery
                Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                //uploading the image
                StorageReference photoRef = mChatPhotosStorageReference.child("writedatabase");
                Log.i("Pritish", "onComplete: "+filePath);
                // Upload file to Firebase Storage
                photoRef.putFile(filePath)
                        .addOnSuccessListener(RegisterActivity.this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                                Uri downloadUrl = taskSnapshot.getDownloadUrl();

                                User user = new User(null, downloadUrl.toString());
                                mMessagesDatabaseReference.push().setValue(user);

                            }
                        });


                //Setting image to ImageView
                cameraImageButton.setImageBitmap(bitmap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

从未调用 addOnSuccessListener . 有人能帮帮我吗 .

1 回答

  • 1

    从addOnSuccessListener参数中删除RegisterActivity.this

相关问题